...# NIY bullet-tt
...$QUOTE = 2; # in blockquote
...sub filter { local($header, *fields, *body) = @_; local(@data) = split(/\n/,$body); $ret = ''; # first pass, process items and hypertext link information for ($i = 0; $i <= $#data; $i++) { $_ = $data[$i]; # $_ is default for m// #
\n" unless $fold++; next; } $fold = 0; # state transitions if (/^>\s/) { &to_quote; } elsif (/^ [^ ]/) { &to_fmt; } else { &to_pre; } s/^>\s*//; # fix quote-tt s/^ ([^ ])/$1/; # fix indent-tt # bold-tt s#\*\*([^\*]*)\*\*#\376B\377$1\376/B\377#; # italic-tt s#~([^~]*)~#\376I\377$1\376/I\377#; # hot-tt s#\b([^\s]*)_\b# $h = $href{$1}; ($a = $1) =~ s,_, ,g; $h ? qq'\376A HREF="$h"\377$a\376/A\377' : "\376I\377$a\376/I\377"; #e; # underline-tt s#_([^\s]*)_# ($a = $1) =~ s,_, ,g; "\376I\377$a\376/I\377"; #e; $ret .= &htmlize($_). "\n"; } &to_fmt; ($ret); } sub to_fmt { return if $curstate == $FMT; $ret .= "\n" if $curstate == $PRE; $ret .= "\n" if $curstate == $QUOTE; #XXX $curstate = $FMT; } sub to_pre { return if $curstate == $PRE; $ret .= "
\n" if $curstate == $FMT; $ret .= "
\n" if $curstate == $QUOTE; #XXX $curstate = $PRE; } sub to_quote { return if $curstate == $QUOTE; $ret .= "\n" if $curstate == $FMT; #XXX $ret .= "\n" if $curstate == $PRE; #XXX $curstate = $QUOTE; } sub htmlize { local($_) = @_; s/\&/\&\#38\;/g; s/\\&\#60\;/g; s/\>/\&\#62\;/g; s/\376//g; # convert back $_; } sub title { local($head, $i) = @_; $data[$i--] = ".."; $data[$i] =~ s/^\s*//; # $ret .= "$data[$i] \n" unless $title++; $data[$i] = ".. <$head>" . $data[$i] . "$head>"; } 1;