ikiwiki/IkiWiki/Plugin/hnb.pm

59 lines
1.2 KiB
Perl
Raw Normal View History

2008-06-15 22:25:18 +02:00
#!/usr/bin/perl
# hnb markup
# Licensed under the GPL v2 or greater
2008-06-15 22:25:18 +02:00
# Copyright (C) 2008 by Axel Beckert <abe@deuxchevaux.org>
#
# TODO: Make a switch to allow both HTML export routines of hnb
# (`export_html` and `export_htmlcss`) to be used.
2008-06-15 22:25:18 +02:00
package IkiWiki::Plugin::hnb;
2008-06-15 22:25:18 +02:00
use warnings;
use strict;
use IkiWiki 3.00;
2008-06-15 22:25:18 +02:00
use File::Temp qw(:mktemp);
sub import {
hook(type => "getsetup", id => "hnb", call => \&getsetup);
hook(type => "htmlize", id => "hnb", call => \&htmlize);
}
2008-06-15 22:25:18 +02:00
sub getsetup () {
return
plugin => {
safe => 1,
rebuild => 1, # format plugin
2010-02-12 07:10:36 +01:00
section => "format",
},
}
sub htmlize (@) {
my %params = @_;
2008-06-15 22:25:18 +02:00
# hnb outputs version number etc. every time to STDOUT, so
# using files makes it easier to seprarate.
2008-06-15 22:25:18 +02:00
my $tmpin = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
2008-06-15 22:25:18 +02:00
open(TMP, '>', $tmpin) or die "Can't write to $tmpin: $!";
print TMP $params{content};
close TMP;
2008-06-15 22:25:18 +02:00
system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
unlink $tmpin;
2008-06-15 22:25:18 +02:00
open(TMP, '<', $tmpout) or die "Can't read from $tmpout: $!";
local $/;
my $ret = <TMP>;
close TMP;
unlink $tmpout;
2008-06-15 22:25:18 +02:00
$ret =~ s/.*<body>//si;
$ret =~ s/<body>.*//si;
2008-06-15 22:25:18 +02:00
return $ret;
}
2008-06-15 22:25:18 +02:00
1;