summaryrefslogtreecommitdiff
path: root/lib/VNDB/Func.pm
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2008-12-29 13:42:58 +0100
committerYorhel <git@yorhel.nl>2008-12-29 13:42:58 +0100
commit3c1b01ec2ba0328f74aa7269bae8015cf1faf531 (patch)
tree32be3bc4696399abf14e09f1f8f78f38f92509dc /lib/VNDB/Func.pm
parent1ef9db32e893669cc5da7b69b371ef051008b989 (diff)
parentf000aaf69e345bae4fc5581e5028463c85cfdafb (diff)
Merge branch 'beta'2.1
Diffstat (limited to 'lib/VNDB/Func.pm')
-rw-r--r--lib/VNDB/Func.pm35
1 files changed, 28 insertions, 7 deletions
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 9abacad0..330dad7d 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -86,6 +86,7 @@ sub userstr {
# [url=..] [/url]
# [raw] .. [/raw]
# [spoiler] .. [/spoiler]
+# [quote] .. [/quote]
# v+, v+.+
# http://../
sub bb2html {
@@ -94,11 +95,10 @@ sub bb2html {
$raw =~ s/\r//g;
return '' if !$raw && $raw ne "0";
- my($result, $length, @open) = ('', 0, 'first');
+ my($result, $length, $rmnewline, @open) = ('', 0, 0, 'first');
my $e = sub {
local $_ = shift;
- tr/A-Za-z/N-ZA-Mn-za-m/ if !@_ && grep /spoiler/, @open;
s/&/&amp;/g;
s/>/&gt;/g;
s/</&lt;/g;
@@ -109,13 +109,34 @@ sub bb2html {
for (split /(\s|\n|\[[^\]]+\])/, $raw) {
next if !defined $_;
+ next if $_ eq '';
+
+ $rmnewline = s/\n//g if $rmnewline;
+ next if $_ eq '';
my $lit = $_;
if($open[$#open] ne 'raw') {
if ($_ eq '[raw]') { push @open, 'raw'; next }
- elsif ($_ eq '[spoiler]') { push @open, 'spoiler'; next }
- elsif ($_ eq '[/spoiler]') { pop @open if $open[$#open] eq 'spoiler'; next }
- elsif ($_ eq '[/url]') {
+ elsif ($_ eq '[spoiler]') { push @open, 'spoiler'; $result .= '<b class="spoiler">'; next }
+ elsif ($_ eq '[quote]') {
+ push @open, 'quote';
+ $result .= '<div class="quote">' if !$maxlength;
+ $rmnewline++;
+ next
+ } elsif ($_ eq '[/spoiler]') {
+ if($open[$#open] eq 'spoiler') {
+ $result .= '</b>';
+ pop @open;
+ }
+ next;
+ } elsif ($_ eq '[/quote]') {
+ if($open[$#open] eq 'quote') {
+ $result .= '</div>' if !$maxlength;
+ $rmnewline++;
+ pop @open;
+ }
+ next;
+ } elsif($_ eq '[/url]') {
if($open[$#open] eq 'url') {
$result .= '</a>';
pop @open;
@@ -126,7 +147,7 @@ sub bb2html {
push @open, 'url';
next;
} elsif(!grep(/url/, @open) &&
- s{(.*)(http|https)://(.+[0-9a-zA-Z=/])(.*)}
+ s{(.*)(http|https)://(.+[\d\w=/-])(.*)}
{$e->($1).qq|<a href="$2://|.$e->($3, 1).'" rel="nofollow">'.$e->('link').'</a>'.$e->($4)}e) {
$length += 4;
last if $maxlength && $length > $maxlength;
@@ -151,7 +172,7 @@ sub bb2html {
$result .= $e->($_);
}
- $result .= '</a>'
+ $result .= $_ eq 'url' ? '</a>' : $_ eq 'quote' ? '</div>' : '</b>'
while((local $_ = pop @open) ne 'first');
$result .= '...' if $maxlength && $length > $maxlength;