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