]> sipb.mit.edu Git - ikiwiki.git/blob - doc/patchqueue/html_tidy_plugin.mdwn
a8b9f2728d83eb93a87b0b410b6b0ee49f6bb083
[ikiwiki.git] / doc / patchqueue / html_tidy_plugin.mdwn
1 Obvious and straightforward ;-)
2 tidy should be probably added to Suggests -- doc/ikiwiki.setup should also be updated.  
3 (yes, I'm too lazy today...)
4
5 -- [[Faidon]]
6
7 ---
8
9         #!/usr/bin/perl
10         # HTML Tidy plugin
11         # requires 'tidy' binary, found in Debian or http://tidy.sf.net/
12         # mostly a proof-of-concept on how to use external filters.
13         # It is particularly useful when the html plugin is used.
14         package IkiWiki::Plugin::tidy;
15         
16         use warnings;
17         use strict;
18         use IkiWiki;
19         use IPC::Open2;
20         
21         sub import { #{{{
22                 IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
23         } # }}}
24         
25         sub sanitize ($) { #{{{
26                 open2(*IN, *OUT, 'tidy -quiet -xml -indent -utf8') or return shift;
27                 # open2 doesn't respect "use open ':utf8'"
28                 binmode (IN, ':utf8'); 
29                 binmode (OUT, ':utf8'); 
30         
31                 print OUT shift;
32                 close OUT;
33         
34                 local $/ = undef;
35                 return <IN>;
36         } # }}}
37         
38         1