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

Now with extra flavour! PerlMonks-ish links, finer control over header tags, italic, strikethrough and teletype text for your HTML-hating enjoyment!
--- /usr/local/lib/perl5/site_perl/5.005/HTML/FromText.pm Wed Oc +t 6 04:53 :37 1999 +++ FromText.pm Sat Sep 7 16:26:57 2002 @@ -85,6 +85,24 @@ s|\b((?:$protocol):\S+[\w/])|<TT><A HREF="$1">$1</A></TT>|g; } + # PATCH + # NAMED URLS: mark up named URLs of the form [url name]. Do this + only + # if urls isn't set. + # Matt Olson June 2nd 2002 + if ($options->{named_urls} and !$options->{urls}) { + s|\[((?: + (?:$protocol) # match a possible protocol + :// # followed by this thing + )? + \S+ # followed by the URL, until a space + ) + \s+ # ignore whitespace + ([^\]]+) # read description text until trailing ] + \] + |<A HREF="$1">$2</A>|xg; + } + # END PATCH + # BOLD: mark up words in *asterisks* as bold. if ($options->{bold}) { s#(^|\s)\*([^*]+)\*(?=\s|$)#$1<B>$2</B>#g; @@ -94,6 +112,31 @@ if ($options->{underline}) { s#(^|\s)_([^_]+?)_(?=\s|$)#$1<U>$2</U>#g; } + + # PATCH + # ITALICS: mark up words between /slashes/ as italicized. + # If underline isn't set, do the same for words in _underscores_. + # Matt Olson, June 1st 2002 + if ($options->{italics}) { + s#(^|\s)/([^/]+?)/(?=\s|$)#$1<I>$2</I>#g; + if (!$options->{underline}) { + s#(^|\s)_([^_]+?)_(?=\s|$)#$1<I>$2</I>#g; + } + } + + # FIXED-WIDTH: mark up words between +plusses+ as fixed-width. + # (Mnemonic: '+' looks like a 't' in <tt> + # Matt Olson, June 28th 2002 + if ($options->{fixed_width}) { + s#(^|\s)\+([^\+]+?)\+(?=\s|$)#$1<TT>$2</TT>#g; + } + + # STRIKE-THROUGH: mark up words between -hyphens- as struck throu +gh. + # Matt Olson, June 28th 2002 + if ($options->{strike_through}) { + s#(^|\s)\-([^\-]+?)\-(?=\s|$)#$1<STRIKE>$2</STRIKE>#g; + } + # END PATCH } return $_[0]; @@ -182,6 +225,17 @@ (?:\s*\n # Either 1 or more blank lines, +or |(?=\s*(?:\d+)[.\)\]]?\s+)) # numbered item follows. /x; + # PATCH + # Headers + # Recognize leading #N as a level-N header, and markup *-led para +s as + # H4s. + # Matt Olson, 2002 June 3 + } elsif ($options{headers}) { + @paras = split + /(?:\s*\n)+ # (0 or more blank lines, followe +d by LF) + (?:\s*\n # Either 1 or more blank lines, +or + |(?=\s*(?:\#\d|[*-])\s+)) # headered item follows. + /x; } else { @paras = split /\s*\n(?:\s*\n)+ # 1 or more blank lines. @@ -213,6 +267,18 @@ s|^|<H$level>|; s|$|</H$level>|; } + + # PATCH + # HEADERS: mark up paragraphs starting with bullets or #N as he +adings. + # Matt Olson, 2002 June 3 + elsif ($options{headers} and /^\s*(\#\d|[*-])\s+/) { + my ($level) = ($1 =~ /(\d)/); + $level = 4 unless $level; + string2html($_,\%options); + s/^\s*(?:\#\d|[*-])\s+/<H$level>/; + s/$/<\/H$level>/; + } + # END PATCH # BULLETS: mark up paragraphs starting with bullets as items in + an # unnumbered list.