PHP语法高亮 [英] PHP syntax highlighting

查看:163
本文介绍了PHP语法高亮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个可以自定义的 PHP语法突出显示引擎(即,我可以为新语言提供我的自己的令牌生成器),并且可以处理多种语言同时(即在同一输出页面上).该引擎必须与 CSS类一起很好地工作,即,它应该通过插入装饰有class属性的<span>元素来格式化输出.可扩展架构的奖励点.

I'm searching for a PHP syntax highlighting engine that can be customized (i.e. I can provide my own tokenizers for new languages) and that can handle several languages simultaneously (i.e. on the same output page). This engine has to work well together with CSS classes, i.e. it should format the output by inserting <span> elements that are adorned with class attributes. Bonus points for an extensible schema.

搜索客户端语法突出显示脚本(JavaScript).

I do not search for a client-side syntax highlighting script (JavaScript).

到目前为止,我一直坚持使用 GeSHi .不幸的是,GeSHi失败的原因很多.主要原因是不同的语言文件定义了完全不同的,不一致的样式.我已经花了几个小时试图将不同的语言定义重构为一个通用的分母,但是由于大多数定义文件本身都非常糟糕,所以我最终想切换.

So far, I'm stuck with GeSHi. Unfortunately, GeSHi fails abysmally for several reasons. The main reason is that the different language files define completely different, inconsistent styles. I've worked hours trying to refactor the different language definitions down to a common denominator but since most definition files are in themselves quite bad, I'd finally like to switch.

理想情况下,我想拥有一个类似于 CodeRay dp.SyntaxHighlighter .

Ideally, I'd like to have an API similar to CodeRay, Pygments or the JavaScript dp.SyntaxHighlighter.

我正在寻找一种代码突出显示软件,该代码突出显示是用 PHP编写的,而不是 for PHP(因为我需要在PHP内部使用它).

I'm looking for a code highlighting software written in PHP, not for PHP (since I need to use it from inside PHP).

推荐答案

由于没有现有的工具可以满足我的需求,因此我编写了自己的工具.看吧:

Since no existing tool satisfied my needs, I wrote my own. Lo and behold:

使用非常简单:只需使用

Usage is extremely easy: just use

 <?php hyperlight($code, 'php'); ?>

突出显示代码.使用正则表达式和功能强大但简单的状态机,编写新的语言定义也相对容易.顺便说一句,我仍然需要很多定义,所以随时可以贡献力量.

to highlight code. Writing new language definitions is relatively easy, too – using regular expressions and a powerful but simple state machine. By the way, I still need a lot of definitions so feel free to contribute.

这篇关于PHP语法高亮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆