]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/hnb.pm
avoid storing transient state in pagestate
[ikiwiki.git] / IkiWiki / Plugin / hnb.pm
1 #!/usr/bin/perl
2 # hnb markup
3 # Licensed under the GPL v2 or greater
4 # Copyright (C) 2008 by Axel Beckert <abe@deuxchevaux.org>
5
6 # TODO: Make a switch to allow both HTML export routines of hnb 
7 # (`export_html` and `export_htmlcss`) to be used.
8
9 package IkiWiki::Plugin::hnb;
10
11 use warnings;
12 use strict;
13 use IkiWiki 2.00;
14 use File::Temp qw(:mktemp);
15
16 sub import {
17         hook(type => "getsetup", id => "hnb", call => \&getsetup);
18         hook(type => "htmlize", id => "hnb", call => \&htmlize);
19 }
20
21 sub getsetup () {
22         return
23                 plugin => {
24                         safe => 1,
25                         rebuild => 1, # format plugin
26                 },
27 }
28
29 sub htmlize (@) {
30         my %params = @_;
31
32         # hnb outputs version number etc. every time to STDOUT, so
33         # using files makes it easier to seprarate.
34
35         my $tmpin  = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX"  );
36         my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
37
38         open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
39         print TMP $params{content};
40         close TMP;
41
42         system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
43         unlink $tmpin;
44
45         open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
46         local $/;
47         my $ret = <TMP>;
48         close TMP;
49         unlink $tmpout;
50
51         $ret =~ s/.*<body>//si;
52         $ret =~ s/<body>.*//si;
53
54         return $ret;
55 }
56
57 1;