Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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.

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 igelkott (Curate) on Mar 13, 2013 at 00:22 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
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1023082]
Approved by igelkott
[ambrus]: the directory structure may be 1, 2, or 3 deep, it may have spaces in the filename or not, it has dates in various format, different keywords for the same meanings, and the dates and other keywords are assembled in various ways.
[Discipulus]: no ambrus by specification i mean for example license per core instead of per socket, so fields are different

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (13)
As of 2017-03-29 12:19 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (351 votes). Check out past polls.