From: Michael Andreen Date: Sun, 25 Jan 2009 18:45:50 +0000 (+0100) Subject: Switch to Parse::BBCode X-Git-Url: https://ruin.nu/git/?a=commitdiff_plain;h=2c8cd1ee01b115d3c0290a2050bbb076aa6508dc;hp=b34d60e2292fd751d6baa3bf26f561687dbcb5f6;p=ndwebbie.git Switch to Parse::BBCode --- diff --git a/lib/NDWeb/Include.pm b/lib/NDWeb/Include.pm index 5c8ba9c..8105dad 100644 --- a/lib/NDWeb/Include.pm +++ b/lib/NDWeb/Include.pm @@ -21,7 +21,7 @@ package NDWeb::Include; use strict; use warnings; require Exporter; -use BBCode::Parser; +use Parse::BBCode; use CGI qw/:standard/; our @ISA = qw/Exporter/; @@ -40,21 +40,35 @@ sub comma_value ($) { return $v; } + +my $bbc = Parse::BBCode->new({ + tags => { + Parse::BBCode::HTML->defaults, + '' => sub { + my $e = ($_[2]); + $e =~ s/\r?\n|\r/
\n/g; + $e + }, + url => 'url:%s', + quote => 'block:
+
%{html}a wrote:
+
%s
', + code => 'block:
%{html}s
', + img => 'url:%s', + li => 'block:
  • %{parse}s
  • ', + }, + close_open_tags => 1, + }); + sub parseMarkup ($) { my ($text) = @_; - #$text =~ s{\n}{\n
    }g; - #$text =~ s{\[B\](.*?)\[/B\]}{$1}gi; - #$text =~ s{\[I\](.*?)\[/I\]}{$1}gi; - #$text =~ s{\[url\](.*?)\[/url\]}{$1}gi; - #$text =~ s{\[PRE\](.*?)\[/PRE\]}{
    $1
    }sgi; - #$text =~ s{\[PRE\](.*?)\[/PRE\]}{
    $1
    }sgi; - #$1 =~ s{
    }{}g; - - eval{ - my $tree = BBCode::Parser->DEFAULT->parse($text); - $text = $tree->toHTML; - }; + $text = $bbc->render($text); + if ($bbc->error){ + my $tree = $bbc->get_tree; + $text = $tree->raw_text; + $text = $bbc->render($text); + } $text =~ s/\x{3}\d\d?//g; #mirc color TODO: possibly match until \x{0F} and change to [color] block $text =~ s/[^\x{9}\x{A}\x{D}\x{20}-\x{D7FF}\x{E000}-\x{FFFD}\x{10000}-\x{10FFFF}]//g; return $text; diff --git a/root/lib/site/html.tt2 b/root/lib/site/html.tt2 index 46b1824..066abb1 100644 --- a/root/lib/site/html.tt2 +++ b/root/lib/site/html.tt2 @@ -19,7 +19,7 @@