summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmlpacker.pm
blob: 39a90b0adfee60584b7a31832405687dcc21bdb3 (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Plugin::htmlpacker;
  3. # htmlpacker: HTML code cleaner
  4. #
  5. # Copyright 2011 Jonas Smedegaard <dr@jones.dk>
  6. # Based on htmlbalance which is...
  7. # Copyright 2008 Simon McVittie <http://smcv.pseudorandom.co.uk/>
  8. # Licensed under the GNU GPL, version 2, or any later version published by the
  9. # Free Software Foundation
  10. use warnings;
  11. use strict;
  12. use IkiWiki 3.00;
  13. sub import {
  14. hook(type => "getsetup", id => "hmtlpacker", call => \&getsetup);
  15. hook(type => "sanitize", id => "hmtlpacker", call => \&sanitize);
  16. }
  17. sub getsetup () {
  18. return
  19. plugin => {
  20. safe => 1,
  21. rebuild => undef,
  22. },
  23. }
  24. sub sanitize (@) {
  25. my %params=@_;
  26. my $ret = '';
  27. eval q{use HTML::Packer};
  28. error $@ if $@;
  29. my $packer = HTML::Packer->init();
  30. $ret = $packer->minify( \$params{content}, { html5 => $config{html5} } );
  31. return $ret;
  32. }
  33. 1