Slash Boxes
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 ]

agent (5836)


Agent Zhang (章亦春) is a happy Yahoo! China guy who loves Perl more than anything else.

Journal of agent (5836)

Saturday September 27, 2008
10:23 PM

pod2html.js: Some JavaScript love for POD in a browser

[ #37558 ]
It's fun to do POD (Plain Old Documentation) in a web browser and I've hacked up a JavaScript implementation for the pod2html utility (actually the output is more like Pod::Simple::HTML).

The pod2html.js script is in OpenResty's SVN repository:

The API is straightforward, for instance,

   var pod = "=head1 Blah\n\nI<Hello>, C<world>!\n";
   var html = pod2html(pod);

The following web site is already making use of it:

By sniffing the background AJAX requests (e.g. using Firebug), you can see raw POD is retrieved from the OpenResty server and converted to HTML on-the-fly in your browser.

It's worth mentioning that I had a lot of fun combining Test::Base and JavaScript::SpiderMonkey to test this piece of JavaScript code in pure Perl. You can checkout the test script here:

By looking at the (declarative) test cases, it's trivial to see what it can do (and hopefully what it can't) :)

For the record, as of this writing, the following POD directives are supported:

  =headN, =over, =item *, =item NUM., =item TEXT, =back, =begin html, =end html, =begin ANY, =end ANY, =cut (it's a no-op), =encoding ANY (it's a no-op)

and the following POD markups are implemented:

   C<...>, I<...>, B<...>, L<...>, F<...>

I've also implemented the (non-standard) =image directive for convenience. For example,

   =image gate.jpg

will be converted to

   <p><img src="gate.jpg"/></p>

Have fun!

P.S. This journal was originally posted to my personal blog site:

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.