diff options
author | Yorhel <git@yorhel.nl> | 2009-11-09 17:06:45 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2009-11-09 17:07:25 +0100 |
commit | e4b912bc68cebff9c42ef17e7356e9cf5a218272 (patch) | |
tree | f889f7738e40621b106243aa7d3dc9ae8adf3cd6 /lib/VNDB/Func.pm | |
parent | 70f0408500a37c1e3ce9fc68a5b894babf62b7c8 (diff) |
bb2html: Added [code] tag and fixed a minor bug
The previous version also had a problem with closing tags when a
$maxlength was defined. With $maxlength, not all tags actually open a
tag in HTML, after all.
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r-- | lib/VNDB/Func.pm | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm index ad38215e..49df0121 100644 --- a/lib/VNDB/Func.pm +++ b/lib/VNDB/Func.pm @@ -22,6 +22,7 @@ sub shorten { # [raw] .. [/raw] # [spoiler] .. [/spoiler] # [quote] .. [/quote] +# [code] .. [/code] # v+, v+.+ # http://../ sub bb2html { @@ -51,7 +52,7 @@ sub bb2html { $rmnewline-- && $_ eq "\n" && next if $rmnewline; my $lit = $_; - if($open[$#open] ne 'raw') { + if($open[$#open] ne 'raw' && $open[$#open] ne 'code') { if (lc$_ eq '[raw]') { push @open, 'raw'; next } elsif (lc$_ eq '[spoiler]') { push @open, 'spoiler'; $result .= '<b class="spoiler">'; next } elsif (lc$_ eq '[quote]') { @@ -59,6 +60,11 @@ sub bb2html { $result .= '<div class="quote">' if !$maxlength; $rmnewline = 1; next + } elsif (lc$_ eq '[code]') { + push @open, 'code'; + $result .= '<pre>' if !$maxlength; + $rmnewline = 1; + next } elsif (lc$_ eq '[/spoiler]') { if($open[$#open] eq 'spoiler') { $result .= '</b>'; @@ -97,8 +103,12 @@ sub bb2html { $result .= $_; next; } - } elsif(lc$_ eq '[/raw]') { - pop @open if $open[$#open] eq 'raw'; + } elsif($open[$#open] eq 'raw' && lc$_ eq '[/raw]') { + pop @open; + next; + } elsif($open[$#open] eq 'code' && lc$_ eq '[/code]') { + $result .= '</pre>' if !$maxlength; + pop @open; next; } @@ -108,8 +118,11 @@ sub bb2html { $result .= $e->($_); } - $result .= $_ eq 'url' ? '</a>' : $_ eq 'quote' ? '</div>' : '</b>' - while((local $_ = pop @open) ne 'first'); + # close open tags + while((local $_ = pop @open) ne 'first') { + $result .= $_ eq 'url' ? '</a>' : $_ eq 'spoiler' ? '</b>' : ''; + $result .= $_ eq 'quote' ? '</div>' : $_ eq 'code' ? '</pre>' : '' if !$maxlength; + } $result .= '...' if $maxlength && $length > $maxlength; return $result; |