Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

jj (2990)

jj
  (email not shown publicly)
http://perl.jonallen.info/

Software development manager for OpusVL [opusvl.com], member of Birmingham Perl Mongers [pm.org] and maintainer of http://perldoc.perl.org [perl.org].

Follow me on Twitter at twitter.com/JJ_Perl [twitter.com].

Journal of jj (2990)

Tuesday April 17, 2007
03:22 PM

Ajax Perl syntax highlighting

[ #33014 ]

I've put together a set of scripts to dynamically apply Perl syntax highlighting to code examples on web pages.

It uses Perl::Tidy to perform the highlighting, and the OpenThought Ajax library to run the requests asynchronously so that initial page load times will not be affected by the extra processing.

Files and examples are available from http://perl.jonallen.info/projects/syntaxhighlighting.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Any idea how well Perl::Tidy compares to PPI::HTML ? I whipped together a code folder/compressor [presicient.com] for PPI::HTML, but haven't had time to get it CPAN ready yet, and am in mind to add some add'l behaviors. PPI::HTML tends to be a bit sluggish, but I'm wondering if it does a more complete tagging of language elements than Tidy ?
    • PPI::HTML is the most accurate of all of the syntax highlighters, by a significant margin, especially when you hit things like heredocs and complex regular expressions and so on.

      The only problem is that, yes, PPI and therefore PPI::HTML are resource pigs. Parsing Perl is Hard :)

      Personally, I use PPI::HTML when I can afford the CPU or I'm caching a lot, and the rest of the time I don't bother at all.
      • Thnx. I kinda figured as much, but thought I'd double check. Since my effort is for a debugger, I need as precise a parse as possible, so I'll stick w/ PPI::HTML (I already have a caching mechanism in place).
      • > The only problem is that, yes, PPI and therefore PPI::HTML are resource pigs. Parsing Perl is Hard :)

        Well, perltidy is also quite big ... almost 1MB of source code!

        If you have an ActiveState distrib, there is also the ActiveState::ScinePlex module which is quite good. I played with both ScinePlex and PPI while designing Pod::POM::Web, and found that the results are quite similar

        • > Well, perltidy is also quite big ... almost 1MB of source code!

          That's mostly because it runs exceptionally evilly, from what I could tell reading it, it doesn't parse perl so much as nudge whitespace around.

          And I believe it's actually a good deal faster.

          And finally, PerlTidy doesn't actually do any syntax highlighting from what I understand, it just does the whitespace-shifting work, he'd have to be highlighting using something else.
          • PerlTidy doesn’t actually do any syntax highlighting

            Yes it does. In HTML mode it will spit out coloured code.