]> sipb.mit.edu Git - ikiwiki.git/blob - IkiWiki/Plugin/hnb.pm
Merge commit 'intrigeri/pedigree'
[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 => "htmlize", id => "hnb", call => \&htmlize);
18 }
19
20 sub htmlize (@) {
21         my %params = @_;
22
23         # hnb outputs version number etc. every time to STDOUT, so
24         # using files makes it easier to seprarate.
25
26         my $tmpin  = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX"  );
27         my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
28
29         open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
30         print TMP $params{content};
31         close TMP;
32
33         system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
34         unlink $tmpin;
35
36         open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
37         local $/;
38         my $ret = <TMP>;
39         close TMP;
40         unlink $tmpout;
41
42         $ret =~ s/.*<body>//si;
43         $ret =~ s/<body>.*//si;
44
45         return $ret;
46 }
47
48 1;