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