diff options
author | Yorhel <git@yorhel.nl> | 2018-01-06 12:58:21 +0100 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2018-01-06 12:58:21 +0100 |
commit | 11963a54f3e86812e9bd3f542da57d1163c9d5ff (patch) | |
tree | 80d70c4595f0b7a9bfecfb04f48fc84a1fb5b7cb /lib/VNDB/BBCode.pm | |
parent | 1ad717b9ebce12938aaa55ac17d086f69fb18fea (diff) |
Add bb2text() and use it for release notes & open graph tags
Diffstat (limited to 'lib/VNDB/BBCode.pm')
-rw-r--r-- | lib/VNDB/BBCode.pm | 25 |
1 files changed, 24 insertions, 1 deletions
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; |