summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Multi/Feed.pm2
-rw-r--r--lib/VNDB/BBCode.pm132
-rw-r--r--lib/VNDB/Func.pm2
-rw-r--r--lib/VNDB/Handler/Misc.pm2
-rw-r--r--lib/VNDB/Handler/Tags.pm2
-rw-r--r--lib/VNDB/Handler/Traits.pm2
-rw-r--r--lib/VNDB/Handler/VNPage.pm2
-rw-r--r--lib/VNWeb/Chars/Page.pm4
-rw-r--r--lib/VNWeb/Discussions/Thread.pm4
-rw-r--r--lib/VNWeb/Discussions/UPosts.pm2
-rw-r--r--lib/VNWeb/HTML.pm6
-rw-r--r--lib/VNWeb/Misc/BBCode.pm2
-rw-r--r--lib/VNWeb/Misc/History.pm2
-rw-r--r--lib/VNWeb/Misc/Reports.pm4
-rw-r--r--lib/VNWeb/Producers/Page.pm4
-rw-r--r--lib/VNWeb/Releases/Lib.pm2
-rw-r--r--lib/VNWeb/Releases/Page.pm4
-rw-r--r--lib/VNWeb/Reviews/Page.pm2
-rw-r--r--lib/VNWeb/Reviews/VNTab.pm2
-rw-r--r--lib/VNWeb/Staff/Page.pm4
-rw-r--r--lib/VNWeb/VN/Page.pm4
-rwxr-xr-xutil/bbcode-test.pl56
22 files changed, 124 insertions, 122 deletions
diff --git a/lib/Multi/Feed.pm b/lib/Multi/Feed.pm
index be367bbc..ad52bace 100644
--- a/lib/Multi/Feed.pm
+++ b/lib/Multi/Feed.pm
@@ -114,7 +114,7 @@ sub write_atom {
$x->end;
}
$x->tag(link => rel => 'alternate', type => 'text/html', href => config->{url}.$_->{id}, undef);
- $x->tag('summary', type => 'html', bb2html $_->{summary}) if $_->{summary};
+ $x->tag('summary', type => 'html', bb_format $_->{summary}) if $_->{summary};
$x->end('entry');
}
diff --git a/lib/VNDB/BBCode.pm b/lib/VNDB/BBCode.pm
index a5050eab..ecba3e58 100644
--- a/lib/VNDB/BBCode.pm
+++ b/lib/VNDB/BBCode.pm
@@ -5,7 +5,7 @@ use warnings;
use Exporter 'import';
use TUWF::XML 'xml_escape';
-our @EXPORT = qw/bb2html bb2text bb_subst_links/;
+our @EXPORT = qw/bb_format bb_subst_links/;
# Supported BBCode:
# [b] .. [/b]
@@ -173,117 +173,111 @@ FINAL:
}
-# charspoil:
-# 0/undef/missing: Output <b class="spoiler">..
-# 1: Deprecated
-# 2: Just output 'hidden by spoiler setting' message
-# 3: Just output the spoilers, unmarked
-sub bb2html {
- my($input, $maxlength, $charspoil, $nobreak) = @_;
+# Options:
+# maxlength => 0/$n - truncate after $n visible characters
+# inline => 0/1 - don't insert line breaks and don't format block elements
+#
+# One of:
+# text => 0/1 - format as plain text, no tags
+# onlyids => 0/1 - format as HTML, but only convert VNDBIDs, leave the rest alone (including [spoiler]s)
+# default: format all to HTML.
+#
+# One of:
+# delspoil => 0/1 - delete [spoiler] tags and its contents
+# replacespoil => 0/1 - replace [spoiler] tags with a "hidden by spoiler settings" message
+# keepsoil => 0/1 - keep the contents of spoiler tags without any special formatting
+# default: format as <b class="spoiler">..
+sub bb_format {
+ my($input, %opt) = @_;
+ $opt{delspoil} = 1 if $opt{text} && !$opt{keepspoil};
my $incode = 0;
+ my $inspoil = 0;
my $rmnewline = 0;
my $length = 0;
my $ret = '';
# escapes, returns string, and takes care of $length and $maxlength; also
# takes care to remove newlines and double spaces when necessary
- my $e = sub {
+ my sub e {
local $_ = shift;
s/^\n// if $rmnewline && $rmnewline--;
s/\n{5,}/\n\n/g if !$incode;
s/ +/ /g if !$incode;
$length += length $_;
- if($maxlength && $length > $maxlength) {
- $_ = substr($_, 0, $maxlength-$length);
+ if($opt{maxlength} && $length > $opt{maxlength}) {
+ $_ = substr($_, 0, $opt{maxlength}-$length);
s/\W+\w*$//; # cleanly cut off on word boundary
}
- s/&/&amp;/g;
- s/>/&gt;/g;
- s/</&lt;/g;
- s/\n/<br>/g if !$nobreak;
- s/\n/ /g if $nobreak;
+ if(!$opt{text}) {
+ s/&/&amp;/g;
+ s/>/&gt;/g;
+ s/</&lt;/g;
+ s/\n/<br>/g if !$opt{inline};
+ }
+ s/\n/ /g if $opt{inline};
$_;
};
parse $input, sub {
my($raw, $tag, @arg) = @_;
- #$ret .= "$tag {$raw}\n";
- #return 1;
+ return 1 if $inspoil && $tag ne 'spoiler_end' && ($opt{delspoil} || $opt{replacespoil});
if($tag eq 'text') {
- $ret .= $e->($raw);
-
- } elsif($tag eq 'b_start') { $ret .= '<b>';
- } elsif($tag eq 'b_end') { $ret .= '</b>';
- } elsif($tag eq 'i_start') { $ret .= '<em>';
- } elsif($tag eq 'i_end') { $ret .= '</em>';
- } elsif($tag eq 'u_start') { $ret .= '<span class="underline">';
- } elsif($tag eq 'u_end') { $ret .= '</span>';
- } elsif($tag eq 's_start') { $ret .= '<s>';
- } elsif($tag eq 's_end') { $ret .= '</s>';
-
- } elsif($tag eq 'spoiler_start') {
- $ret .= !$charspoil ? '<b class="spoiler">' :
- $charspoil == 2 ? '<b class="grayedout">&lt;hidden by spoiler settings&gt;</b><!--' : '';
- } elsif($tag eq 'spoiler_end') {
- $ret .= !$charspoil ? '</b>' :
- $charspoil == 2 ? '-->' : '';
+ $ret .= e $raw;
+ } elsif($tag eq 'dblink') {
+ (my $link = $raw) =~ s/^d(\d+)\.(\d+)\.(\d+)$/d$1#$2.$3/;
+ $ret .= $opt{text} ? e $raw : sprintf '<a href="/%s">%s</a>', $link, e $raw;
+
+ } elsif($opt{idonly}) {
+ $ret .= e $raw;
+
+ } elsif($tag eq 'b_start') { $ret .= $opt{text} ? e '*' : '<b>'
+ } elsif($tag eq 'b_end') { $ret .= $opt{text} ? e '*' : '</b>'
+ } elsif($tag eq 'i_start') { $ret .= $opt{text} ? e '/' : '<em>'
+ } elsif($tag eq 'i_end') { $ret .= $opt{text} ? e '/' : '</em>'
+ } elsif($tag eq 'u_start') { $ret .= $opt{text} ? e '_' : '<span class="underline">'
+ } elsif($tag eq 'u_end') { $ret .= $opt{text} ? e '_' : '</span>'
+ } elsif($tag eq 's_start') { $ret .= $opt{text} ? e '-' : '<s>'
+ } elsif($tag eq 's_end') { $ret .= $opt{text} ? e '-' : '</s>'
} elsif($tag eq 'quote_start') {
- $ret .= '<div class="quote">' if !$nobreak;
+ $ret .= $opt{text} || $opt{inline} ? e '"' : '<div class="quote">';
$rmnewline = 1;
} elsif($tag eq 'quote_end') {
- $ret .= '</div>' if !$nobreak;
+ $ret .= $opt{text} || $opt{inline} ? e '"' : '</div>';
$rmnewline = 1;
} elsif($tag eq 'code_start') {
- $ret .= '<pre>' if !$nobreak;
+ $ret .= $opt{text} || $opt{inline} ? e '`' : '<pre>';
$rmnewline = 1;
$incode = 1;
} elsif($tag eq 'code_end') {
- $ret .= '</pre>' if !$nobreak;
+ $ret .= $opt{text} || $opt{inline} ? e '`' : '</pre>';
$rmnewline = 1;
$incode = 0;
+ } elsif($tag eq 'spoiler_start') {
+ $inspoil = 1;
+ $ret .= $opt{delspoil} || $opt{keepspoil} ? ''
+ : $opt{replacespoil} ? '<b class="grayedout">&lt;hidden by spoiler settings&gt;</b>'
+ : '<b class="spoiler">';
+ } elsif($tag eq 'spoiler_end') {
+ $inspoil = 0;
+ $ret .= $opt{delspoil} || $opt{keepspoil} || $opt{replacespoil} ? '' : '</b>';
+
} elsif($tag eq 'url_start') {
- $ret .= sprintf '<a href="%s" rel="nofollow">', xml_escape($arg[0]);
+ $ret .= $opt{text} ? '' : sprintf '<a href="%s" rel="nofollow">', xml_escape($arg[0]);
} elsif($tag eq 'url_end') {
- $ret .= '</a>';
+ $ret .= $opt{text} ? '' : '</a>';
} elsif($tag eq 'link') {
- $ret .= sprintf '<a href="%s" rel="nofollow">%s</a>', xml_escape($raw), $e->('link');
-
- } elsif($tag eq 'dblink') {
- (my $link = $raw) =~ s/^d(\d+)\.(\d+)\.(\d+)$/d$1#$2.$3/;
- $ret .= sprintf '<a href="/%s">%s</a>', $link, $e->($raw);
+ $ret .= $opt{text} ? e $raw : sprintf '<a href="%s" rel="nofollow">%s</a>', xml_escape($raw), e 'link';
}
- !$maxlength || $length < $maxlength;
- };
- $ret;
-}
-
-
-# Convert bbcode into plain text, stripping all tags and spoilers. [url] tags
-# only display the title.
-sub bb2text {
- my $input = shift;
-
- my $inspoil = 0;
- my $ret = '';
- parse $input, sub {
- my($raw, $tag, @arg) = @_;
- if($tag eq 'spoiler_start') {
- $inspoil = 1;
- } elsif($tag eq 'spoiler_end') {
- $inspoil = 0;
- } else {
- $ret .= $raw if !$inspoil && $tag !~ /_(start|end)$/;
- }
- 1;
+ !$opt{maxlength} || $length < $opt{maxlength};
};
$ret;
}
diff --git a/lib/VNDB/Func.pm b/lib/VNDB/Func.pm
index 2a169552..2fcd5b54 100644
--- a/lib/VNDB/Func.pm
+++ b/lib/VNDB/Func.pm
@@ -10,7 +10,7 @@ use JSON::XS;
use VNDBUtil;
use VNDB::Types;
use VNDB::BBCode;
-our @EXPORT = (@VNDBUtil::EXPORT, 'bb2html', 'bb2text', qw|
+our @EXPORT = (@VNDBUtil::EXPORT, 'bb_format', qw|
clearfloat cssicon minage fil_parse fil_serialize parenttags
childtags charspoil imgpath imgurl
fmtvote fmtmedia fmtvnlen fmtage fmtdatestr fmtdate fmtrating fmtspoil
diff --git a/lib/VNDB/Handler/Misc.pm b/lib/VNDB/Handler/Misc.pm
index 906c7c78..b7e1620d 100644
--- a/lib/VNDB/Handler/Misc.pm
+++ b/lib/VNDB/Handler/Misc.pm
@@ -105,7 +105,7 @@ sub homepage {
a href => "/$_->{id}", $_->{title};
end;
p;
- lit bb2html $post->{msg}, 150, 0, 1;
+ lit bb_format $post->{msg}, maxlength => 150, inline => 1;
end;
}
end 'td';
diff --git a/lib/VNDB/Handler/Tags.pm b/lib/VNDB/Handler/Tags.pm
index c44529cf..55bf99db 100644
--- a/lib/VNDB/Handler/Tags.pm
+++ b/lib/VNDB/Handler/Tags.pm
@@ -83,7 +83,7 @@ sub tagpage {
if($t->{description}) {
p class => 'description';
- lit bb2html $t->{description};
+ lit bb_format $t->{description};
end;
}
if(!$t->{applicable} || !$t->{searchable}) {
diff --git a/lib/VNDB/Handler/Traits.pm b/lib/VNDB/Handler/Traits.pm
index f9802cff..e69b673e 100644
--- a/lib/VNDB/Handler/Traits.pm
+++ b/lib/VNDB/Handler/Traits.pm
@@ -64,7 +64,7 @@ sub traitpage {
if($t->{description}) {
p class => 'description';
- lit bb2html $t->{description};
+ lit bb_format $t->{description};
end;
}
if(!$t->{applicable} || !$t->{searchable}) {
diff --git a/lib/VNDB/Handler/VNPage.pm b/lib/VNDB/Handler/VNPage.pm
index 1e11aa7b..1198a421 100644
--- a/lib/VNDB/Handler/VNPage.pm
+++ b/lib/VNDB/Handler/VNPage.pm
@@ -149,7 +149,7 @@ my @rel_cols = (
default => 1,
what => 'extended',
has_data => sub { !!$_[0]{notes} },
- draw => sub { lit bb2html $_[0]{notes} },
+ draw => sub { lit bb_format $_[0]{notes} },
}
);
diff --git a/lib/VNWeb/Chars/Page.pm b/lib/VNWeb/Chars/Page.pm
index 2accc94b..b131b7e9 100644
--- a/lib/VNWeb/Chars/Page.pm
+++ b/lib/VNWeb/Chars/Page.pm
@@ -213,7 +213,7 @@ sub chartable_ {
tr_ class => 'nostripe', sub {
td_ colspan => 2, class => 'chardesc', sub {
h2_ 'Description';
- p_ sub { lit_ bb2html $c->{desc}, 0, $view->{spoilers} == 2 ? 3 : 2 };
+ p_ sub { lit_ bb_format $c->{desc}, delspoil => $view->{spoilers} != 2, keepspoil => $view->{spoilers} == 2 };
};
} if $c->{desc};
};
@@ -251,7 +251,7 @@ TUWF::get qr{/$RE{crev}} => sub {
framework_ title => $c->{name}, index => !tuwf->capture('rev'), type => 'c', dbobj => $c, hiddenmsg => 1,
og => {
- description => bb2text($c->{desc}),
+ description => bb_format($c->{desc}, text => 1),
image => $c->{image} && $c->{image}{votecount} && !$c->{image}{sexual} && !$c->{image}{violence} ? tuwf->imgurl($c->{image}{id}) : undef,
},
sub {
diff --git a/lib/VNWeb/Discussions/Thread.pm b/lib/VNWeb/Discussions/Thread.pm
index bafe5449..80b7e544 100644
--- a/lib/VNWeb/Discussions/Thread.pm
+++ b/lib/VNWeb/Discussions/Thread.pm
@@ -70,7 +70,7 @@ elm_api DiscussionsReply => $REPLY_OUT, $REPLY_IN, sub {
sub metabox_ {
my($t) = @_;
div_ class => 'mainbox', sub {
- h1_ sub { lit_ bb2html $t->{title} };
+ h1_ sub { lit_ bb_format $t->{title}, idonly => 1 };
h2_ 'Hidden' if $t->{hidden};
h2_ 'Private' if $t->{private};
h2_ 'Locked' if $t->{locked};
@@ -125,7 +125,7 @@ sub posts_ {
if($_->{hidden}) {
i_ class => 'deleted', 'Post deleted.';
} else {
- lit_ bb2html $_->{msg};
+ lit_ bb_format $_->{msg};
i_ class => 'lastmod', 'Last modified on '.fmtdate($_->{edited}, 'full') if $_->{edited};
}
};
diff --git a/lib/VNWeb/Discussions/UPosts.pm b/lib/VNWeb/Discussions/UPosts.pm
index 46bb0977..d3bfa95c 100644
--- a/lib/VNWeb/Discussions/UPosts.pm
+++ b/lib/VNWeb/Discussions/UPosts.pm
@@ -24,7 +24,7 @@ sub listing_ {
td_ class => 'tc3', fmtdate $_->{date};
td_ class => 'tc4', sub {
a_ href => $url, $_->{title};
- b_ class => 'grayedout', sub { lit_ bb2html $_->{msg}, 150, 0, 1 };
+ b_ class => 'grayedout', sub { lit_ bb_format $_->{msg}, maxlength => 150, inline => 1 };
};
} for @$list;
}
diff --git a/lib/VNWeb/HTML.pm b/lib/VNWeb/HTML.pm
index 1a4dc617..772f3ebc 100644
--- a/lib/VNWeb/HTML.pm
+++ b/lib/VNWeb/HTML.pm
@@ -418,7 +418,7 @@ sub _hidden_msg_ {
txt_ ' if you believe that this entry should be restored.';
br_;
br_;
- lit_ bb2html $msg;
+ lit_ bb_format $msg;
}
}
};
@@ -614,7 +614,7 @@ sub _revision_cmp_ {
b_ "Edit summary for revision $new->{chrev}";
br_;
br_;
- lit_ bb2html $new->{rev_comments}||'-';
+ lit_ bb_format $new->{rev_comments}||'-';
};
};
};
@@ -677,7 +677,7 @@ sub revision_ {
br_;
b_ 'Edit summary';
br_; br_;
- lit_ bb2html $new->{rev_comments}||'-';
+ lit_ bb_format $new->{rev_comments}||'-';
} if !$old;
_revision_cmp_ $type, $old, $new, @fields if $old;
diff --git a/lib/VNWeb/Misc/BBCode.pm b/lib/VNWeb/Misc/BBCode.pm
index 5d6f2e0b..2c41b6da 100644
--- a/lib/VNWeb/Misc/BBCode.pm
+++ b/lib/VNWeb/Misc/BBCode.pm
@@ -5,7 +5,7 @@ use VNWeb::Prelude;
elm_api BBCode => undef, {
content => { required => 0, default => '' }
}, sub {
- elm_Content bb2html bb_subst_links shift->{content};
+ elm_Content bb_format bb_subst_links shift->{content};
};
1;
diff --git a/lib/VNWeb/Misc/History.pm b/lib/VNWeb/Misc/History.pm
index 0959eb91..927afa98 100644
--- a/lib/VNWeb/Misc/History.pm
+++ b/lib/VNWeb/Misc/History.pm
@@ -80,7 +80,7 @@ sub tablebox_ {
td_ class => 'tc3', sub { user_ $i };
td_ class => 'tc4', sub {
a_ href => $revurl, title => $i->{original}, shorten $i->{title}, 80;
- b_ class => 'grayedout', sub { lit_ bb2html $i->{comments}, 150, 0, 1 };
+ b_ class => 'grayedout', sub { lit_ bb_format $i->{comments}, maxlength => 150, inline => 1 };
};
} for @$lst;
};
diff --git a/lib/VNWeb/Misc/Reports.pm b/lib/VNWeb/Misc/Reports.pm
index b932cd31..c275efa9 100644
--- a/lib/VNWeb/Misc/Reports.pm
+++ b/lib/VNWeb/Misc/Reports.pm
@@ -130,7 +130,7 @@ sub report_ {
lit_ $r->{title} || '[deleted]';
br_;
txt_ $r->{reason};
- div_ class => 'quote', sub { lit_ bb2html $r->{message} } if $r->{message};
+ div_ class => 'quote', sub { lit_ bb_format $r->{message} } if $r->{message};
};
td_ style => 'width: 300px', sub {
form_ method => 'post', action => '/report/edit', sub {
@@ -145,7 +145,7 @@ sub report_ {
};
};
td_ sub {
- lit_ bb2html $r->{log};
+ lit_ bb_format $r->{log};
};
}
diff --git a/lib/VNWeb/Producers/Page.pm b/lib/VNWeb/Producers/Page.pm
index 802218d6..eac6f3e4 100644
--- a/lib/VNWeb/Producers/Page.pm
+++ b/lib/VNWeb/Producers/Page.pm
@@ -59,7 +59,7 @@ sub info_ {
}, grep $rel{$_}, keys %PRODUCER_RELATION;
} if $p->{relations}->@*;
- p_ class => 'description', sub { lit_ bb2html $p->{desc} } if length $p->{desc};
+ p_ class => 'description', sub { lit_ bb_format $p->{desc} } if length $p->{desc};
}
@@ -155,7 +155,7 @@ TUWF::get qr{/$RE{prev}(?:/(?<tab>vn|rel))?}, sub {
framework_ title => $p->{name}, index => !tuwf->capture('rev'), type => 'p', dbobj => $p, hiddenmsg => 1,
og => {
title => $p->{name},
- description => bb2text($p->{desc}),
+ description => bb_format($p->{desc}, text => 1),
},
sub {
rev_ $p if tuwf->capture('rev');
diff --git a/lib/VNWeb/Releases/Lib.pm b/lib/VNWeb/Releases/Lib.pm
index 87f9c401..4aad7b50 100644
--- a/lib/VNWeb/Releases/Lib.pm
+++ b/lib/VNWeb/Releases/Lib.pm
@@ -92,7 +92,7 @@ sub release_row_ {
}
icon_ $MEDIUM{ $r->{media}[0]{medium} }{icon}, join ', ', map fmtmedia($_->{medium}, $_->{qty}), $r->{media}->@* if $r->{media}->@*;
icon_ 'uncensor', 'Uncensored' if $r->{uncensored};
- icon_ 'notes', bb2text $r->{notes} if $r->{notes};
+ icon_ 'notes', bb_format $r->{notes}, text => 1 if $r->{notes};
}
tr_ sub {
diff --git a/lib/VNWeb/Releases/Page.pm b/lib/VNWeb/Releases/Page.pm
index d7cbb745..e60d84b6 100644
--- a/lib/VNWeb/Releases/Page.pm
+++ b/lib/VNWeb/Releases/Page.pm
@@ -212,7 +212,7 @@ TUWF::get qr{/$RE{rrev}} => sub {
framework_ title => $r->{title}, index => !tuwf->capture('rev'), type => 'r', dbobj => $r, hiddenmsg => 1,
og => {
- description => bb2text $r->{notes}
+ description => bb_format $r->{notes}, text => 1
},
sub {
_rev_ $r if tuwf->capture('rev');
@@ -221,7 +221,7 @@ TUWF::get qr{/$RE{rrev}} => sub {
h1_ sub { txt_ $r->{title}; debug_ $r };
h2_ class => 'alttitle', lang_attr($r->{lang}), $r->{original} if length $r->{original};
_infotable_ $r;
- p_ class => 'description', sub { lit_ bb2html $r->{notes} } if $r->{notes};
+ p_ class => 'description', sub { lit_ bb_format $r->{notes} } if $r->{notes};
};
};
};
diff --git a/lib/VNWeb/Reviews/Page.pm b/lib/VNWeb/Reviews/Page.pm
index 36ed8ee2..55847bf6 100644
--- a/lib/VNWeb/Reviews/Page.pm
+++ b/lib/VNWeb/Reviews/Page.pm
@@ -60,7 +60,7 @@ sub review_ {
} if $w->{spoiler};
tr_ @spoil, sub {
td_ 'Review';
- td_ sub { lit_ bb2html $w->{text} }
+ td_ sub { lit_ bb_format $w->{text} }
};
tr_ sub {
td_ '';
diff --git a/lib/VNWeb/Reviews/VNTab.pm b/lib/VNWeb/Reviews/VNTab.pm
index bd1ae870..9b5427d1 100644
--- a/lib/VNWeb/Reviews/VNTab.pm
+++ b/lib/VNWeb/Reviews/VNTab.pm
@@ -40,7 +40,7 @@ sub reviews_ {
a_ href => "/report/$r->{id}", 'report';
txt_ '>';
};
- my $html = bb2html $r->{text}, $mini ? undef : 700;
+ my $html = bb_format $r->{text}, maxlength => $mini ? undef : 700;
$html .= '...' if !$mini;
if($r->{spoiler}) {
label_ class => 'review_spoil', sub {
diff --git a/lib/VNWeb/Staff/Page.pm b/lib/VNWeb/Staff/Page.pm
index 72227559..8f6e0897 100644
--- a/lib/VNWeb/Staff/Page.pm
+++ b/lib/VNWeb/Staff/Page.pm
@@ -171,7 +171,7 @@ TUWF::get qr{/$RE{srev}} => sub {
framework_ title => $main->{name}, index => !tuwf->capture('rev'), type => 's', dbobj => $s, hiddenmsg => 1,
og => {
- description => bb2text $s->{desc}
+ description => bb_format $s->{desc}, text => 1
},
sub {
_rev_ $s if tuwf->capture('rev');
@@ -180,7 +180,7 @@ TUWF::get qr{/$RE{srev}} => sub {
h1_ sub { txt_ $main->{name}; debug_ $s };
h2_ class => 'alttitle', lang => $s->{lang}, $main->{original} if $main->{original};
_infotable_ $main, $s;
- p_ class => 'description', sub { lit_ bb2html $s->{desc} };
+ p_ class => 'description', sub { lit_ bb_format $s->{desc} };
};
_roles_ $s;
diff --git a/lib/VNWeb/VN/Page.pm b/lib/VNWeb/VN/Page.pm
index 0692a076..683e3af0 100644
--- a/lib/VNWeb/VN/Page.pm
+++ b/lib/VNWeb/VN/Page.pm
@@ -49,7 +49,7 @@ sub enrich_item {
sub og {
my($v) = @_;
+{
- description => bb2text($v->{desc}),
+ description => bb_format($v->{desc}, text => 1),
image => $v->{image} && !$v->{image}{sexual} && !$v->{image}{violence} ? tuwf->imgurl($v->{image}{id}) :
[map $_->{scr}{sexual}||$_->{scr}{violence}?():(tuwf->imgurl($_->{scr}{id})), $v->{screenshots}->@*]->[0]
}
@@ -375,7 +375,7 @@ sub infobox_ {
tr_ class => 'nostripe', sub {
td_ class => 'vndesc', colspan => 2, sub {
h2_ 'Description';
- p_ sub { lit_ $v->{desc} ? bb2html $v->{desc} : '-' };
+ p_ sub { lit_ $v->{desc} ? bb_format $v->{desc} : '-' };
}
}
}
diff --git a/util/bbcode-test.pl b/util/bbcode-test.pl
index 230277b5..e306c952 100755
--- a/util/bbcode-test.pl
+++ b/util/bbcode-test.pl
@@ -12,7 +12,7 @@ use Benchmark 'timethese';
our($ROOT, %S);
BEGIN { ($ROOT = abs_path $0) =~ s{/util/bbcode-test\.pl$}{}; }
use lib "$ROOT/lib";
-use VNDB::BBCode qw/bb2html bb2text/;
+use VNDB::BBCode;
my @tests = (
@@ -30,11 +30,11 @@ my @tests = (
'[quote]some quote[/quote]',
'<div class="quote">some quote</div>',
- 'some quote',
+ '"some quote"',
"[code]some code\n\nalso newlines;[/code]",
'<pre>some code<br><br>also newlines;</pre>',
- "some code\n\nalso newlines;",
+ "`some code\n\nalso newlines;`",
'[spoiler]some spoiler[/spoiler]',
'<b class="spoiler">some spoiler</b>',
@@ -42,7 +42,7 @@ my @tests = (
'[b][i][u][s]Formatting![/s][/u][/i][/b]',
'<b><em><span class="underline"><s>Formatting!</s></span></em></b>',
- 'Formatting!',
+ '*/_-Formatting!-_/*',
"[raw][quote]not parsed\n[url=https://vndb.org/]valid url[/url]\n[url=asdf]invalid url[/url][/quote][/raw]",
"[quote]not parsed<br>[url=https://vndb.org/]valid url[/url]<br>[url=asdf]invalid url[/url][/quote]",
@@ -50,11 +50,11 @@ my @tests = (
'[quote]basic [spoiler]single[/spoiler]-line [spoiler][url=/g]tag[/url] nesting [raw](without [url=/v3333]special[/url] cases)[/raw][/spoiler][/quote]',
'<div class="quote">basic <b class="spoiler">single</b>-line <b class="spoiler"><a href="/g" rel="nofollow">tag</a> nesting (without [url=/v3333]special[/url] cases)</b></div>',
- 'basic -line ',
+ '"basic -line "',
'[quote][b]more [spoiler]nesting [code]mkay?',
'<div class="quote"><b>more <b class="spoiler">nesting [code]mkay?</b></b></div>',
- 'more ',
+ '"*more *"',
'[url=/v][b]does not work here[/b][/url]',
'<a href="/v" rel="nofollow">[b]does not work here[/b]</a>',
@@ -62,11 +62,11 @@ my @tests = (
'[s] v5 [url=/p1]x[/url] [/s]',
'<s> <a href="/v5">v5</a> <a href="/p1" rel="nofollow">x</a> </s>',
- ' v5 x ',
+ '- v5 x -',
"[quote]rmnewline after closing tag[/quote]\n",
'<div class="quote">rmnewline after closing tag</div>',
- "rmnewline after closing tag\n",
+ "\"rmnewline after closing tag\"",
'[url=/v19]some vndb url[/url]',
'<a href="/v19" rel="nofollow">some vndb url</a>',
@@ -74,20 +74,20 @@ my @tests = (
"quite\n\n\n\n\n\n\na\n\n\n\n\n lot of\n\n\n\nunneeded whitespace",
'quite<br><br>a<br><br> lot of<br><br><br><br>unneeded whitespace',
- "quite\n\n\n\n\n\n\na\n\n\n\n\n lot of\n\n\n\nunneeded whitespace",
+ "quite\n\na\n\n lot of\n\n\n\nunneeded whitespace",
"[quote]\nsimple\nrmnewline\ntest\n[/quote]",
'<div class="quote">simple<br>rmnewline<br>test<br></div>',
- "\nsimple\nrmnewline\ntest\n",
+ "\"simple\nrmnewline\ntest\n\"",
# the new implementation doesn't special-case [code], as the first newline shouldn't matter either way
"[quote]\n\nhello, rmnewline test[code]\n#!/bin/sh\n\nfunction random_username() {\n </dev/urandom tr -cd 'a-zA-Z0-9' | dd bs=1 count=16 2>/dev/null\n}\n[/code]\nsome text after the code tag\n[/quote]\n\n[spoiler]\nsome newlined spoiler\n[/spoiler]",
'<div class="quote"><br>hello, rmnewline test<pre>#!/bin/sh<br><br>function random_username() {<br> &lt;/dev/urandom tr -cd \'a-zA-Z0-9\' | dd bs=1 count=16 2&gt;/dev/null<br>}<br></pre>some text after the code tag<br></div><br><b class="spoiler"><br>some newlined spoiler<br></b>',
- "\n\nhello, rmnewline test\n#!/bin/sh\n\nfunction random_username() {\n </dev/urandom tr -cd 'a-zA-Z0-9' | dd bs=1 count=16 2>/dev/null\n}\n\nsome text after the code tag\n\n\n",
+ "\"\nhello, rmnewline test`#!/bin/sh\n\nfunction random_username() {\n </dev/urandom tr -cd 'a-zA-Z0-9' | dd bs=1 count=16 2>/dev/null\n}\n`some text after the code tag\n\"\n",
"[quote]\n[raw]\nrmnewline test with made-up elements\n[/raw]\nwelp\n[dumbtag]\nnone\n[/dumbtag]\n[/quote]",
'<div class="quote"><br>rmnewline test with made-up elements<br><br>welp<br>[dumbtag]<br>none<br>[/dumbtag]<br></div>',
- "\n\nrmnewline test with made-up elements\n\nwelp\n[dumbtag]\nnone\n[/dumbtag]\n",
+ "\"\nrmnewline test with made-up elements\n\nwelp\n[dumbtag]\nnone\n[/dumbtag]\n\"",
'[url=http://example.com/]markup in [raw][url][/raw][/url]',
'<a href="http://example.com/" rel="nofollow">markup in [url]</a>',
@@ -111,7 +111,7 @@ my @tests = (
'[Quote]non-lowercase tags [SpOILER]here[/sPOilER][/qUOTe]',
'<div class="quote">non-lowercase tags <b class="spoiler">here</b></div>',
- 'non-lowercase tags ',
+ '"non-lowercase tags "',
'some text [spoiler]with (v17) tags[/spoiler] and internal ids such as s1',
'some text <b class="spoiler">with (<a href="/v17">v17</a>) tags</b> and internal ids such as <a href="/s1">s1</a>',
@@ -152,11 +152,11 @@ my @tests = (
# TODO: This isn't ideal
'[quote][spoiler]stray open tag (nested)[/quote]',
'<div class="quote"><b class="spoiler">stray open tag (nested)[/quote]</b></div>',
- '',
+ '""',
'[quote][spoiler]two stray open tags',
'<div class="quote"><b class="spoiler">two stray open tags</b></div>',
- '',
+ '""',
"[url=https://cat.xyz/]that's [spoiler]some [quote]uncommon[/quote][/spoiler] combination[/url]",
'<a href="https://cat.xyz/" rel="nofollow">that\'s [spoiler]some [quote]uncommon[/quote][/spoiler] combination</a>',
@@ -170,13 +170,21 @@ my @tests = (
#'<a href="http://[fedc:ba98:7654:3210:fedc:ba98:7654:3210]/some/path" rel="nofollow">link</a> (literal ipv6 address)',
# test shortening
- [ "[url=https://cat.xyz/]that's [spoiler]some [quote]uncommon[/quote][/spoiler] combination[/url]", 10 ],
+ [ "[url=https://cat.xyz/]that's [spoiler]some [quote]uncommon[/quote][/spoiler] combination[/url]", maxlength => 10 ],
'<a href="https://cat.xyz/" rel="nofollow">that\'s </a>',
- "that's [spoiler]some [quote]uncommon[/quote][/spoiler] combination",
+ "that's ",
- [ "A https://blicky.net/ only takes 4 characters", 8 ],
+ [ "A https://blicky.net/ only takes 4 characters", maxlength => 8 ],
'A <a href="https://blicky.net/" rel="nofollow">link</a>',
- "A https://blicky.net/ only takes 4 characters",
+ "A https", # Yeah, uh... word boundary
+
+ [ 'vndbids only [url=/v9]nothing[/url] [b] [spoiler]p5', idonly => 1 ],
+ 'vndbids only [url=/v9]nothing[/url] [b] [spoiler]<a href="/p5">p5</a>',
+ 'vndbids only [url=/v9]nothing[/url] [b] [spoiler]p5',
+
+ [ 'this [spoiler]spoiler will be[/spoiler] kept', keepspoil => 1 ],
+ 'this spoiler will be kept',
+ 'this spoiler will be kept',
);
@@ -212,8 +220,8 @@ sub test {
my @arg = ref $input ? @$input : ($input);
(my $msg = $arg[0]) =~ s/\n/\\n/g;
is identity($arg[0]), $arg[0], "id: $msg";
- is bb2html(@arg), $html, "html: $msg";
- is bb2text($arg[0]), $plain, "plain: $msg";
+ is bb_format(@arg), $html, "html: $msg";
+ is bb_format(@arg, text => 1), $plain, "plain: $msg";
}
}
@@ -224,9 +232,9 @@ sub bench {
my $short = "Nobody ev3r v10 uses v5 so s1 many [url=https://blicky.net/]x[raw]y[/raw][/url] tags. ";
my $heavy = $short x100;
timethese(0, {
- short => sub { bb2html($short) },
- plain => sub { bb2html($plain) },
- heavy => sub { bb2html($heavy) },
+ short => sub { bb_format($short) },
+ plain => sub { bb_format($plain) },
+ heavy => sub { bb_format($heavy) },
});
# old:
# heavy: 3 wallclock secs ( 3.15 usr + 0.00 sys = 3.15 CPU) @ 357.46/s (n=1126)