Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Perl HTML syntax highlighting

by wanna_code_perl (Friar)
on Mar 13, 2013 at 00:11 UTC ( [id://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.

Replies are listed 'Best First'.
Re: Perl HTML syntax highlighting
by saberworks (Curate) on Mar 13, 2013 at 01:19 UTC
Re: Perl HTML syntax highlighting
by tobyink (Canon) 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
Re: Perl HTML syntax highlighting
by igelkott (Priest) on Mar 13, 2013 at 00:22 UTC
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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
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?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2024-04-25 07:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found