summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmltidy.pm
blob: ad405dce581184860b819cd077cc262ff6728875 (plain)
  1. #!/usr/bin/perl
  2. # HTML Tidy plugin
  3. # requires 'tidy' binary, found in Debian or http://tidy.sf.net/
  4. # mostly a proof-of-concept on how to use external filters.
  5. # It is particularly useful when the html plugin is used.
  6. #
  7. # by Faidon Liambotis
  8. package IkiWiki::Plugin::tidy;
  9. use warnings;
  10. use strict;
  11. use IkiWiki;
  12. use IPC::Open2;
  13. sub import { #{{{
  14. IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
  15. } # }}}
  16. sub sanitize ($) { #{{{
  17. open2(*IN, *OUT, 'tidy -quiet -xml -indent -utf8') or return shift;
  18. # open2 doesn't respect "use open ':utf8'"
  19. binmode (IN, ':utf8');
  20. binmode (OUT, ':utf8');
  21. print OUT shift;
  22. close OUT;
  23. local $/ = undef;
  24. return <IN>;
  25. } # }}}
  26. 1