From 11963a54f3e86812e9bd3f542da57d1163c9d5ff Mon Sep 17 00:00:00 2001 From: Yorhel Date: Sat, 6 Jan 2018 12:58:21 +0100 Subject: Add bb2text() and use it for release notes & open graph tags --- lib/VNDB/BBCode.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'lib/VNDB/BBCode.pm') diff --git a/lib/VNDB/BBCode.pm b/lib/VNDB/BBCode.pm index ffa14d98..95a90d16 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/; +our @EXPORT = qw/bb2html bb2text/; # Supported BBCode: # [spoiler] .. [/spoiler] @@ -226,4 +226,27 @@ sub bb2html { $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; + }; + $ret; +} + + 1; -- cgit v1.2.3