aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhttps://www.google.com/accounts/o8/id?id=AItOawnxp2XU8gIribhhGhGuYtU6eMMwHv5gUGI <Amitai@web>2011-06-08 19:41:47 +0000
committeradmin <admin@branchable.com>2011-06-08 19:41:47 +0000
commitf2dca770da6b7d7e56195e84ae804f1cb5c466b3 (patch)
tree65712797b48c1dfde0de819015ce7b78ab8ec8a1
parentee7ff1486fa31b7bc3d95f95ec5d72c7562339d1 (diff)
downloadikiwiki-f2dca770da6b7d7e56195e84ae804f1cb5c466b3.tar
ikiwiki-f2dca770da6b7d7e56195e84ae804f1cb5c466b3.tar.gz
t3h c0d35
-rw-r--r--doc/plugins/contrib/mandoc.mdwn52
1 files changed, 52 insertions, 0 deletions
diff --git a/doc/plugins/contrib/mandoc.mdwn b/doc/plugins/contrib/mandoc.mdwn
index e541c194e..e4ff96d08 100644
--- a/doc/plugins/contrib/mandoc.mdwn
+++ b/doc/plugins/contrib/mandoc.mdwn
@@ -6,3 +6,55 @@ This plugin lets ikiwiki convert Unix man pages to HTML. It uses
xrefs into hyperlinks.
Sample output: <http://wiki.netbsd.org/users/schmonz/tunefs.8/>
+
+-----
+
+
+ #!/usr/bin/perl
+ package IkiWiki::Plugin::mandoc;
+
+ use warnings;
+ use strict;
+ use IkiWiki 3.00;
+ use Encode;
+ use IPC::Open2;
+
+ sub import {
+ hook(type => "getsetup", id => "mandoc", call => \&getsetup);
+ hook(type => "htmlize", id => $_, call => \&htmlize, keepextension => 1)
+ foreach ('man', 1..9);
+ }
+
+ sub getsetup () {
+ return
+ plugin => {
+ safe => 1,
+ rebuild => 1, # format plugin
+ section => "format",
+ },
+ }
+
+ sub htmlize (@) {
+ my %params=@_;
+ my $content = decode_utf8(encode_utf8($params{content}));
+
+ return $content if $@;
+
+ my $pid = open2(*MANDOCOUT, *MANDOCIN, 'mandoc', '-Thtml');
+ binmode($_, ':utf8') foreach (*MANDOCOUT, *MANDOCIN);
+
+ print MANDOCIN $content;
+ close MANDOCIN;
+ my @html_output = <MANDOCOUT>;
+ close MANDOCOUT;
+ waitpid $pid, 0;
+
+ my $html = join('', @html_output);
+ my $link_prefix = $config{usedirs} ? '../' : '';
+ my $link_suffix = $config{usedirs} ? '/' : '';
+ $html =~ s|<a class="link-man">(.+?)\((.)\)</a>|<a class="link-man" href="$link_prefix$1.$2$link_suffix">$1($2)</a>|g;
+
+ return $html;
+ }
+
+ 1