summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmlscrubber.pm
blob: 8e83918170b3b8f4d11a0fed369675338eedcaca (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. }, "/" => 1, # emit proper <hr /> XHTML
  42. }],
  43. );
  44. return $_scrubber;
  45. } # }}}
  46. 1