Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Perl HTML syntax highlighting

by wanna_code_perl (Pilgrim)
on Mar 13, 2013 at 00:11 UTC ( #1023082=perlquestion: print w/ replies, xml ) Need Help??
wanna_code_perl has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks!

I need a way to apply syntax highlighting to Perl code. (Mostly short snippets.) I do not require support for any other languages, although some rudimentary checking to differentiate Perl from non-Perl plain text would be a bonus. I realize nothing can parse Perl but perl, and this will not be an exact science, but it doesn't need to be; I just need it to 1) parse the snippets pretty well, most of the time (or fail somewhat gracefully if things get out of hand), and 2) not modify the code itself.

After some false starts with others, I spent a few hours with Perl::Tidy's formatter/write_line API with limited success. It seems to entirely discard lines of tokens if it gets even slightly confused, so my only recourse is to abandon the highlighting and render the source as plain text when that happens. I had less success with other mods.

I do have a slight preference for a server-side (Perl) implementation so I can pre-compile and cache all the XHTML to reduce page render times, thus the reason I'm asking here on perlmonks instead of a JS forum.

Comment on Perl HTML syntax highlighting
Download Code
Re: Perl HTML syntax highlighting
by Anonymous Monk on Mar 13, 2013 at 00:20 UTC

    I'm not sure I understand, what is the problem with Perl::Tidy ?

    I think it works well

    There is always PPI::HTML among others

Re: Perl HTML syntax highlighting
by igelkott (Curate) on Mar 13, 2013 at 00:22 UTC
Re: Perl HTML syntax highlighting
by saberworks (Curate) on Mar 13, 2013 at 01:19 UTC
Re: Perl HTML syntax highlighting
by tobyink (Abbot) on Mar 13, 2013 at 08:20 UTC

    My recommendation is PPI::HTML for syntax highlighting Perl, and Syntax::Highlight::Engine::Kate for syntax highlighting anything else.

    package Cow { use Moo; has name => (is => 'lazy', default => sub { 'Mooington' }) } say Cow->new->name

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1023082]
Approved by igelkott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-11-28 15:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (198 votes), past polls