2006-05-05 07:41:11 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
package IkiWiki::Plugin::htmlscrubber;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2007-04-27 04:55:52 +02:00
|
|
|
use IkiWiki 2.00;
|
2006-05-05 07:41:11 +02:00
|
|
|
|
|
|
|
sub import { #{{{
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize);
|
2006-05-05 07:41:11 +02:00
|
|
|
} # }}}
|
|
|
|
|
2006-08-28 20:17:59 +02:00
|
|
|
sub sanitize (@) { #{{{
|
|
|
|
my %params=@_;
|
|
|
|
return scrubber()->scrub($params{content});
|
2006-05-05 07:41:11 +02:00
|
|
|
} # }}}
|
|
|
|
|
|
|
|
my $_scrubber;
|
|
|
|
sub scrubber { #{{{
|
|
|
|
return $_scrubber if defined $_scrubber;
|
|
|
|
|
|
|
|
eval q{use HTML::Scrubber};
|
2006-11-08 22:03:33 +01:00
|
|
|
error($@) if $@;
|
2006-05-05 07:41:11 +02:00
|
|
|
# Lists based on http://feedparser.org/docs/html-sanitization.html
|
|
|
|
$_scrubber = HTML::Scrubber->new(
|
|
|
|
allow => [qw{
|
|
|
|
a abbr acronym address area b big blockquote br
|
|
|
|
button caption center cite code col colgroup dd del
|
|
|
|
dfn dir div dl dt em fieldset font form h1 h2 h3 h4
|
|
|
|
h5 h6 hr i img input ins kbd label legend li map
|
|
|
|
menu ol optgroup option p pre q s samp select small
|
|
|
|
span strike strong sub sup table tbody td textarea
|
|
|
|
tfoot th thead tr tt u ul var
|
|
|
|
}],
|
2007-07-11 18:50:59 +02:00
|
|
|
default => [undef, { (
|
|
|
|
map { $_ => 1 } qw{
|
|
|
|
abbr accept accept-charset accesskey action
|
|
|
|
align alt axis border cellpadding cellspacing
|
|
|
|
char charoff charset checked cite class
|
|
|
|
clear cols colspan color compact coords
|
|
|
|
datetime dir disabled enctype for frame
|
|
|
|
headers height href hreflang hspace id ismap
|
|
|
|
label lang longdesc maxlength media method
|
|
|
|
multiple name nohref noshade nowrap prompt
|
|
|
|
readonly rel rev rows rowspan rules scope
|
|
|
|
selected shape size span src start summary
|
|
|
|
tabindex target title type usemap valign
|
|
|
|
value vspace width
|
|
|
|
} ),
|
|
|
|
"/" => 1, # emit proper <hr /> XHTML
|
|
|
|
}],
|
2006-05-05 07:41:11 +02:00
|
|
|
);
|
|
|
|
return $_scrubber;
|
|
|
|
} # }}}
|
|
|
|
|
|
|
|
1
|