1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Parse::BBCode;
my %tag_def_html = (
code => {
code => sub {
my $c = $_[2];
$c = Parse::BBCode::escape_html($$c);
"<code>$c</code>"
},
},
perlmonks => 'url:<a href="http://www.perlmonks.org/?node=%{uri|html}a">%{parse}s</a>',
url => 'url:<a href="%{link}a">%{parse}s</a>',
i => '<i>%{parse}s</i>',
b => '<b>%{parse}s</b>',
);
my $bbc2html = Parse::BBCode->new({
tags => {
%tag_def_html,
},
}
);
my $text = <<'EOM';
[i]italic [b]bold italic <html>[/b][/i]
[perlmonks=123]foo <html>[i]italic[/i][/perlmonks]
[url=javascript:alert(123)]foo <html>[i]italic[/i][/url]
[code]foo[b][/code]
[code]foo[code]bar<html>[/code][/code]
[i]italic [b]bold italic <html>[/i][/b]
[b]bold?
EOM
my $parsed = $bbc2html->render($text);
print "$parsed\n";
__DATA__
<i>italic <b>bold italic <html></b></i><br>
<a href="http://www.perlmonks.org/?node=123">foo <html><i>italic</i></a><br>
<a href="">foo <html><i>italic</i></a><br>
<code>foo[b]</code><br>
<code>foo[code]bar<html>[/code]</code><br>
<i>italic [b]bold italic <html></i>[/b]<br>
[b]bold?<br>
|