2008-06-15 22:25:18 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# hnb markup
|
2008-06-15 22:26:15 +02:00
|
|
|
# Licensed under the GPL v2 or greater
|
2008-06-15 22:25:18 +02:00
|
|
|
# Copyright (C) 2008 by Axel Beckert <abe@deuxchevaux.org>
|
2008-06-15 22:26:15 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
2008-06-15 22:26:15 +02:00
|
|
|
package IkiWiki::Plugin::hnb;
|
2008-06-15 22:25:18 +02:00
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-06-15 22:25:18 +02:00
|
|
|
use File::Temp qw(:mktemp);
|
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 22:40:12 +02:00
|
|
|
hook(type => "getsetup", id => "hnb", call => \&getsetup);
|
2008-06-15 22:26:15 +02:00
|
|
|
hook(type => "htmlize", id => "hnb", call => \&htmlize);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-06-15 22:25:18 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 22:40:12 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1, # format plugin
|
2010-02-12 07:10:36 +01:00
|
|
|
section => "format",
|
2008-08-03 22:40:12 +02:00
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 22:40:12 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub htmlize (@) {
|
2008-06-15 22:26:15 +02:00
|
|
|
my %params = @_;
|
2008-06-15 22:25:18 +02:00
|
|
|
|
2008-06-15 22:26:15 +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
|
|
|
|
2010-06-27 19:49:51 +02:00
|
|
|
my ($infh, $tmpin) = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX" );
|
|
|
|
my ($outfh, $tmpout) = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );
|
2008-06-15 22:25:18 +02:00
|
|
|
|
2008-06-15 22:26:15 +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
|
|
|
|
2008-06-15 22:26:15 +02:00
|
|
|
system("hnb '$tmpin' 'go root' 'export_html $tmpout' > /dev/null");
|
|
|
|
unlink $tmpin;
|
2008-06-15 22:25:18 +02:00
|
|
|
|
2008-06-15 22:26:15 +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
|
|
|
|
2008-06-15 22:26:15 +02:00
|
|
|
$ret =~ s/.*<body>//si;
|
|
|
|
$ret =~ s/<body>.*//si;
|
2008-06-15 22:25:18 +02:00
|
|
|
|
2008-06-15 22:26:15 +02:00
|
|
|
return $ret;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-06-15 22:25:18 +02:00
|
|
|
|
|
|
|
1;
|