summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmlscrubber.pm
blob: 540662c2b4d1fcc0cf1c8a0a89d08c3c0eabe280 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::htmlscrubber;
  3. use warnings;
  4. use strict;
  5. use IkiWiki 2.00;
  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, { (
  30. map { $_ => 1 } qw{
  31. abbr accept accept-charset accesskey action
  32. align alt axis border cellpadding cellspacing
  33. char charoff charset checked cite class
  34. clear cols colspan color compact coords
  35. datetime dir disabled enctype for frame
  36. headers height href hreflang hspace id ismap
  37. label lang longdesc maxlength media method
  38. multiple name nohref noshade nowrap prompt
  39. readonly rel rev rows rowspan rules scope
  40. selected shape size span src start summary
  41. tabindex target title type usemap valign
  42. value vspace width
  43. } ),
  44. "/" => 1, # emit proper <hr /> XHTML
  45. }],
  46. );
  47. return $_scrubber;
  48. } # }}}
  49. 1