Package: ikiwiki
Version: 3.20100815.6
Severity: wishlist
Please add hooks for export methods (like htmlize but for other formats).
Attached is what I am trying to accomplish in completely the wrong way.
#!/usr/bin/perl
package IkiWiki::Plugin::export;
use warnings;
use strict;
use IkiWiki 3.00;
use File::Temp;
sub import {
hook(type => "cgi", id => 'goto', call => \&cgi);
hook(type => "getsetup", id => 'goto', call => \&getsetup);
hook(type => "pagetemplate", id => "getsource", call => \&pagetemplate);
}
sub getsetup () {
return
plugin => {
safe => 1,
rebuild => 0,
section => "web",
}
}
# cgi_export(CGI, [page])
# Run a pandoc conversion on the specified page to the specified format.
sub cgi_export ($;$) {
my $q = shift;
my $page = shift;
my $outformat = $q->param("outputformat");
if (!defined $page) {
$page = IkiWiki::decode_utf8($q->param("page"));
if (!defined $page) {
error("missing page parameter");
}
}
if ((!defined $outformat) || ($outformat !~ /^(plain|rst|html|latex|context|man|mediawiki|texinfo|docbook|opendocument|odt|s5|rtf)$/)) {
error("missing or invalid output format");
}
IkiWiki::loadindex();
my $infile = srcfile($pagesources{$page});
printf("Content-Type: application/octet-stream\n");
printf("Content-Disposition: attachment; filename=pandoc_output.%s\n", $outformat);
printf("Content-Description: on-the-fly pandoc export\n\n");
# We could use stdout but for the awfulness that is OpenOffice,
# so we need a temp directory.
my $tempdir = File::Temp::tempdir( CLEANUP => 1 );
system("/usr/bin/pandoc", "-f", "markdown", "-t", $outformat, "-o", $tempdir."/out", $infile);
open(TMPFILE, $tempdir."/out");
binmode(TMPFILE);
binmode(STDOUT);
undef $/;
my $buf = <TMPFILE>;
print "$buf";
close(TMPFILE);
exit;
}
sub cgi ($) {
my $cgi=shift;
my $do = $cgi->param('do');
if (defined $do && ($do eq 'export')) {
cgi_export($cgi);
}
}
sub pagetemplate (@) {
my %params=@_;
my $page=$params{page};
my $template=$params{template};
if (length $config{cgiurl}) {
$template->param(getodturl => IkiWiki::cgiurl(do => "export", page => $page, outputformat => "odt"));
$template->param(getlatexurl => IkiWiki::cgiurl(do => "export", page => $page, outputformat => "latex"));
$template->param(getrtfurl => IkiWiki::cgiurl(do => "export", page => $page, outputformat => "rtf"));
$template->param(have_actions => 1);
}
}
1;