summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmlscrubber.pm
blob: ae3ec44569d3e666ca5abe60f9afc19e5b6643c6 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::htmlscrubber;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. sub import { #{{{
  7. hook(type => "sanitize", id => "htmlscrubber", call => \&sanitize);
  8. } # }}}
  9. sub sanitize (@) { #{{{
  10. my %params=@_;
  11. return scrubber()->scrub($params{content});
  12. } # }}}
  13. my $_scrubber;
  14. sub scrubber { #{{{
  15. return $_scrubber if defined $_scrubber;
  16. eval q{use HTML::Scrubber};
  17. error($@) if $@;
  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