Maybe the idea is a bit sick, but it was the easy way out to avoid having to parse the nesting. The approach is not common: first, I convert the POD document to a piece of code that returns a single string, in this case HTML formatted.

Comments are welcome!

#!/usr/bin/perl -w # unfinished code, possibly insecure. use strict; sub AUTOLOAD { shift }; sub pod_blank { "<p>" } sub pod_code { "<pre>$_[0]</pre>" } sub pod_C { "<tt>$_[0]</tt>" } sub pod_I { "<i>$_[0]</i>" } sub pod_B { "<b>$_[0]</b>" } sub pod_S { "<nobr>$_[0]</nobr>" } sub pod_F { "<tt>$_[0]</tt>" } sub pod_Z { "<span></span>" } sub pod_L { # XXX - needs a lot of work (split /\|/, shift)[0] } sub pod_E { $_[0] =~ /^\d+$/ ? "&#$_[0];" : { qw(lt < gt > sol / verbar |) }->{ $_[0] } || "&$_[0];" } sub pod_head1 { "<h1>$_[0]</h1>" } sub pod_head2 { "<h2>$_[0]</h2>" } sub pod_over { "<ul>" } sub pod_back { "</ul>" } sub pod_item { "<li>$_[0]</li>" } sub pod_PRE { local $_ = shift; s/&/&amp;/g; $_; } sub pod_POST { local $_ = shift; s/</&amp;lt;/g; s/>/&gt;/g; "<html><body>$_</body></html>"; } ### my $pod = do { local $/ = undef; open my $fh, 'pod' or die $!; readline $fh; }; $pod = pod_PRE($pod); $pod =~ s/([\[\]\$\@\\])/\\$1/g; $pod =~ s/^[^\n\S]*$/\${\\ pod_blank() }/gm; $pod =~ s/^=(\w+)(?: ?(.*))?/\${\\ pod_$1(qq[$2]) }/gm; $pod =~ s/^((?:[^\n\S].*\n?)+)/\${\\ pod_code(qq[$1]) }/gm; for (2..6) { my $op = '<' x $_; my $cl = '>' x $_; while ($pod =~ /([IBSCLFXZE])$op (.*?) $cl/) { $pod =~ s//\${\\ pod_$1(qq[$2]) }/g; } } while ($pod =~ /([IBSCLFXZE])<(.*?)>/) { $pod =~ s//\${\\ pod_$1(qq[$2]) }/g; } $pod = 'qq[' . pod_POST($pod) . ']'; print eval $pod;

- Yes, I reinvent wheels.
- Spam: Visit eurotraQ.


In reply to pod2perl and then to html by Juerd

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.