开发者

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

Most PH开发者_如何学CP 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. 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


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


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.


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.


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.


My search brought me here, because I was looking for a 'Perl Syntax Highlighter' like the title said and not an general highlighter implemented in Perl.

To highlight only Perl, perltidy --html can be used. It belongs to the Perl::Tidy distribution the main module can be imported and used without spawning a process.

https://metacpan.org/dist/Perl-Tidy/view/bin/perltidy#HTML-OPTIONS

So not what the OP actually wanted to know, but hopefully of help for others coming here for the same reasons like me ... :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜