]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/otl.pm
kill footer
[ikiwiki.git] / IkiWiki / Plugin / otl.pm
1 #!/usr/bin/perl
2 # outline markup
3 package IkiWiki::Plugin::otl;
4
5 use warnings;
6 use strict;
7 use IkiWiki;
8 use IPC::Open2;
9
10 sub import { #{{{
11         IkiWiki::hook(type => "htmlize", id => "otl", call => \&htmlize);
12 } # }}}
13
14 sub htmlize ($) { #{{{
15         my $tries=10;
16         while (1) {
17                 eval {
18                         open2(*IN, *OUT, 'otl2html -S /dev/null -T /dev/stdin');
19                 };
20                 last unless $@;
21                 $tries--;
22                 if ($tries < 1) {
23                         IkiWiki::debug("failed to run otl2html: $@");
24                         return shift;
25                 }
26         }
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         my $ret=<IN>;
36         $ret=~s/.*<body>//s;
37         $ret=~s/<body>.*//s;
38         $ret=~s/<div class="Footer">.*//s;
39         return $ret;
40 } # }}}
41
42 1