]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/htmlscrubber.pm
d77ab809b7f67ae0e7d3d86842e12ea06a00736b
[ikiwiki.git] / IkiWiki / Plugin / htmlscrubber.pm
1 #!/usr/bin/perl
2 package IkiWiki::Plugin::htmlscrubber;
3
4 use warnings;
5 use strict;
6 use IkiWiki;
7
8 sub import { #{{{
9         IkiWiki::hook(type => "sanitize", id => "htmlscrubber",
10                 call => \&sanitize);
11 } # }}}
12
13 sub sanitize (@) { #{{{
14         my %params=@_;
15         return scrubber()->scrub($params{content});
16 } # }}}
17
18 my $_scrubber;
19 sub scrubber { #{{{
20         return $_scrubber if defined $_scrubber;
21         
22         eval q{use HTML::Scrubber};
23         # Lists based on http://feedparser.org/docs/html-sanitization.html
24         $_scrubber = HTML::Scrubber->new(
25                 allow => [qw{
26                         a abbr acronym address area b big blockquote br
27                         button caption center cite code col colgroup dd del
28                         dfn dir div dl dt em fieldset font form h1 h2 h3 h4
29                         h5 h6 hr i img input ins kbd label legend li map
30                         menu ol optgroup option p pre q s samp select small
31                         span strike strong sub sup table tbody td textarea
32                         tfoot th thead tr tt u ul var
33                 }],
34                 default => [undef, { map { $_ => 1 } qw{
35                         abbr accept accept-charset accesskey action
36                         align alt axis border cellpadding cellspacing
37                         char charoff charset checked cite class
38                         clear cols colspan color compact coords
39                         datetime dir disabled enctype for frame
40                         headers height href hreflang hspace id ismap
41                         label lang longdesc maxlength media method
42                         multiple name nohref noshade nowrap prompt
43                         readonly rel rev rows rowspan rules scope
44                         selected shape size span src start summary
45                         tabindex target title type usemap valign
46                         value vspace width
47                 }, "/" => 1, # emit proper <hr /> XHTML
48                 }],
49         );
50         return $_scrubber;
51 } # }}}
52
53 1