Merge branch 'master' of ssh://git.ikiwiki.info/srv/git/ikiwiki.info
[ikiwiki.git] / IkiWiki / Plugin / hnb.pm
blob5157a6b93ce54c80ffac7330e50033cde57eddb4
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.
9 package IkiWiki::Plugin::hnb;
11 use warnings;
12 use strict;
13 use IkiWiki 3.00;
14 use File::Temp qw(:mktemp);
16 sub import {
17 hook(type => "getsetup", id => "hnb", call => \&getsetup);
18 hook(type => "htmlize", id => "hnb", call => \&htmlize);
21 sub getsetup () {
22 return
23 plugin => {
24 safe => 1,
25 rebuild => 1, # format plugin
26 section => "format",
30 sub htmlize (@) {
31 my %params = @_;
33 # hnb outputs version number etc. every time to STDOUT, so
34 # using files makes it easier to seprarate.
36 my ($infh, $tmpin) = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
37 my ($outfh, $tmpout) = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
39 open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
40 print TMP $params{content};
41 close TMP;
43 system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
44 unlink $tmpin;
46 open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
47 local $/;
48 my $ret = <TMP>;
49 close TMP;
50 unlink $tmpout;
52 $ret =~ s/.*<body>//si;
53 $ret =~ s/<body>.*//si;
55 return $ret;