summaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/htmltidy.pm
blob: 6c1fba98e1b98e913ead06258a74ac21050d34de (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::htmltidy;
  9. use warnings;
  10. use strict;
  11. use IkiWiki;
  12. use IPC::Open2;
  13. sub import { #{{{
  14. IkiWiki::hook(type => "format", id => "tidy", call => \&format);
  15. } # }}}
  16. sub format ($) { #{{{
  17. open2(*IN, *OUT, 'tidy -quiet -asxhtml -indent -utf8 --show-warnings no') 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