http://www.perlmonks.org?node_id=264545


in reply to syntax highlighting of code in perlmonks forums

I’d strongly disagree with doing this within the monastery for a ton of reasons, most already hashed out in other posts. That said, I used to see the code sections syntax highlighted.


Well before this site became nicer with XML and CSS support nashdj created pmproxy2 as a rewriting proxy to create his own themes.

I stumbled across Perl::Syntax::Highlight and thought it would be cool to add syntax highlighting to his rewriting proxy. After a bit of work, it provided CSS control over each type of code element. It worked well for my needs at the time, but it has its issues.

Update: Heh, I found some old screenshots from it. Here, here, and one from rewriting perl.com here.

Now that the site is cleaner (XML, CSS, etc.), I’ve been meaning to rewrite it properly. I have a framework using XML::SAX and Apache + mod_perl started if you’d be interested in continuing it.

Basically it rewrites the documents using event based rules; calling either XSLT or Perl filters. Using the value of the host header to rewrite URIs to point back to it instead of perlmonks.org, adding syntax highlighting to stand alone code sections and javascript controls to turn the CSS behind them on and off for each section, etc.

The framework and a bunch of the event handler are there, I just don’t really care enough about syntax highlighting anymore to finish it (the new custom CSS feature on the site is enough for me). So if you’re interested either check out the original pmproxy2 or I can email you the code (it’s way to many modules and snippets to post here).

The old code may suit your needs with few changes to the regexps. Parsing HMTL with regexps isn’t great, but the old perlmonks.org killed HTML::Parser more often than not ;).

  • Comment on Re: syntax highlighting of code in perlmonks forums