<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/usr/bin/perl
# hnb markup
# Licensed under the GPL v2 or greater
# Copyright (C) 2008 by Axel Beckert &lt;abe@deuxchevaux.org&gt;
# 
# TODO: Make a switch to allow both HTML export routines of hnb 
# (`export_html` and `export_htmlcss`) to be used.

package IkiWiki::Plugin::hnb;

use warnings;
use strict;
use IkiWiki 2.00;
use File::Temp qw(:mktemp);

sub import { #{{{
	hook(type =&gt; "getsetup", id =&gt; "hnb", call =&gt; \&amp;getsetup);
	hook(type =&gt; "htmlize", id =&gt; "hnb", call =&gt; \&amp;htmlize);
} #}}}

sub getsetup () { #{{{
	return
		plugin =&gt; {
			safe =&gt; 1,
			rebuild =&gt; 1, # format plugin
		},
} #}}}

sub htmlize (@) { #{{{
	my %params = @_;

	# hnb outputs version number etc. every time to STDOUT, so
	# using files makes it easier to seprarate.

	my $tmpin  = mkstemp( "/tmp/ikiwiki-hnbin.XXXXXXXXXX"  );
	my $tmpout = mkstemp( "/tmp/ikiwiki-hnbout.XXXXXXXXXX" );

	open(TMP, '&gt;', $tmpin) or die "Can't write to $tmpin: $!";
	print TMP $params{content};
	close TMP;

	system("hnb '$tmpin' 'go root' 'export_html $tmpout' &gt; /dev/null");
	unlink $tmpin;

	open(TMP, '&lt;', $tmpout) or die "Can't read from $tmpout: $!";
	local $/;
	my $ret = &lt;TMP&gt;;
	close TMP;
	unlink $tmpout;

	$ret =~ s/.*&lt;body&gt;//si;
	$ret =~ s/&lt;body&gt;.*//si;

	return $ret;
} #}}}

1;
</pre></body></html>