]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/htmltidy.pm
* Also generate rel=bookmark links for permalinks.
[ikiwiki.git] / IkiWiki / Plugin / htmltidy.pm
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
10 use warnings;
11 use strict;
12 use IkiWiki;
13 use IPC::Open2;
14
15 sub import { #{{{
16         IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
17 } # }}}
18
19 sub sanitize ($) { #{{{
20         open2(*IN, *OUT, 'tidy -quiet -xml -indent -utf8') or return shift;
21         # open2 doesn't respect "use open ':utf8'"
22         binmode (IN, ':utf8'); 
23         binmode (OUT, ':utf8'); 
24
25         print OUT shift;
26         close OUT;
27
28         local $/ = undef;
29         return <IN>;
30 } # }}}
31
32 1