From e4b912bc68cebff9c42ef17e7356e9cf5a218272 Mon Sep 17 00:00:00 2001 From: Yorhel Date: Mon, 9 Nov 2009 17:06:45 +0100 Subject: 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. --- ChangeLog | 1 + data/docs/9 | 4 ++++ lib/VNDB/Func.pm | 23 ++++++++++++++++++----- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4d8752b8..76c87e22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ git - ? - Implemented proper daemonizing and error handling for Multi - Added basic Makefile - Added public database API + - Added [code] tag to bb2html() 2.8 - 2009-10-24 - Converted relation graphs to use inline SVG diff --git a/data/docs/9 b/data/docs/9 index f5ee46ab..fedbd2b0 100644 --- a/data/docs/9 +++ b/data/docs/9 @@ -62,6 +62,10 @@
[raw]
Show off your formatting code skills by putting anything you don't want to have formatted in a [raw] tag. Any of the formatting codes mentioned above are ignored within a [raw] .. [/raw] block. +
[code]
+ Similar to [raw], except that the text within the [code] .. [/code] block is + formatted in a fixed width font and surrounded by a nice box to keep it + separate from the rest of your post.

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 .= ''; next } elsif (lc$_ eq '[quote]') { @@ -59,6 +60,11 @@ sub bb2html { $result .= '

' if !$maxlength; $rmnewline = 1; next + } elsif (lc$_ eq '[code]') { + push @open, 'code'; + $result .= '
' if !$maxlength;
+        $rmnewline = 1;
+        next
       } elsif (lc$_ eq '[/spoiler]') {
         if($open[$#open] eq 'spoiler') {
           $result .= '';
@@ -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 .= '
' if !$maxlength; + pop @open; next; } @@ -108,8 +118,11 @@ sub bb2html { $result .= $e->($_); } - $result .= $_ eq 'url' ? '' : $_ eq 'quote' ? '
' : '' - while((local $_ = pop @open) ne 'first'); + # close open tags + while((local $_ = pop @open) ne 'first') { + $result .= $_ eq 'url' ? '' : $_ eq 'spoiler' ? '' : ''; + $result .= $_ eq 'quote' ? '' : $_ eq 'code' ? '' : '' if !$maxlength; + } $result .= '...' if $maxlength && $length > $maxlength; return $result; -- cgit v1.2.3