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