Is there a Perl Syntax Highlighter (outputting to HTML) like PHP's GeSHi?

非 Y 不嫁゛ 提交于 2019-12-05 05:23:09

问题


Most PHP Developers are likely familar with the Syntax Highlighter called "GeSHi", which takes code, highlights it, with the use of HTML and CSS:

include('geshi.php');
$source = 'echo "hello, world!";
$language = 'php';
$path = 'geshi/';
$geshi = new GeSHi($source, $language, $path);
echo $geshi->parse_code();

GeSHi Supports a wide range of languages.

I wonder, is there a similar Module for Perl?


回答1:


  1. Perl has a port of Kate highlighting system: Syntax::Highlight::Engine::Kate which seems to be somewhat close to what you need. It appears to be part of Padre.

  2. You also have an option of HTML client side highlighters (logic is obviously JS), such as Google's code prettifyer

  3. Two good lists of syntax highlighting engines are:

    • Wiki syntax highlighting article - among the ones it lists, the Perl ports/APIs seem to exist for Kate and Colorer (Syntax::Highlight::Universal)

    • This very good review of HTML syntax highlighters, which contains a lot of client-side ones such as SHJS and many others.

  4. Please be aware that NONE of those generic highlighters work "100% correctly", the way the syntax highlighters work in good IDEs, because they use regular expressions for approximate parsing instead of lexers for actual language grammar parsing. More details on the Wiki




回答2:


You can also consider this for client side syntax highlighting. http://alexgorbatchev.com/SyntaxHighlighter/




回答3:


I have had some very good results with the PPI::HTML package. It uses PPI to parse the Perl before converting the text to HTML.




回答4:


Pure Perl: Syntax::Highlight::Engine::Kate (there is Kate plugin for Padre IDE).

Wrappers for C libraries: Syntax::Highlight::Universal, Syntax::SourceHighlight.

Using external tools: Text::VimColor, Text::EmacsColor.

Also there are many one-language highlighters on CPAN.




回答5:


You can always write a small php script to make GeSHi usable from command line and then call it within your perl script.
I did this for gitweb so I could leave svn (and websvn) behind for good.



来源:https://stackoverflow.com/questions/4529975/is-there-a-perl-syntax-highlighter-outputting-to-html-like-phps-geshi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!