2006-08-18 23:48:03 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
# outline markup
|
|
|
|
package IkiWiki::Plugin::otl;
|
|
|
|
|
|
|
|
use warnings;
|
|
|
|
use strict;
|
2008-12-23 22:34:19 +01:00
|
|
|
use IkiWiki 3.00;
|
2008-07-09 02:52:30 +02:00
|
|
|
use open qw{:utf8 :std};
|
2006-08-18 23:48:03 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub import {
|
2008-08-03 23:20:21 +02:00
|
|
|
hook(type => "getsetup", id => "otl", call => \&getsetup);
|
2006-09-10 00:50:27 +02:00
|
|
|
hook(type => "htmlize", id => "otl", call => \&htmlize);
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-08-19 20:27:57 +02:00
|
|
|
|
2008-12-17 21:22:16 +01:00
|
|
|
sub getsetup () {
|
2008-08-03 23:20:21 +02:00
|
|
|
return
|
|
|
|
plugin => {
|
|
|
|
safe => 1,
|
|
|
|
rebuild => 1, # format plugin
|
|
|
|
},
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2008-08-03 23:20:21 +02:00
|
|
|
|
2009-09-23 21:11:51 +02:00
|
|
|
sub htmlize (@) {
|
2006-08-19 20:27:57 +02:00
|
|
|
my %params=@_;
|
2009-09-23 21:11:51 +02:00
|
|
|
|
|
|
|
# Munge up check boxes to look a little bit better.
|
2006-09-10 00:50:27 +02:00
|
|
|
my $checked=htmllink($params{page}, $params{page},
|
2007-02-20 04:05:47 +01:00
|
|
|
"smileys/star_on.png", linktext => "[X]");
|
2006-09-10 00:50:27 +02:00
|
|
|
my $unchecked=htmllink($params{page}, $params{page},
|
2007-02-20 04:05:47 +01:00
|
|
|
"smileys/star_off.png", linktext => "[_]");
|
2006-08-19 20:28:40 +02:00
|
|
|
$params{content}=~s/^(\s*)\[X\]\s/${1}$checked /mg;
|
|
|
|
$params{content}=~s/^(\s*)\[_\]\s/${1}$unchecked /mg;
|
2006-08-28 20:17:59 +02:00
|
|
|
|
2006-09-08 22:33:49 +02:00
|
|
|
# Can't use open2 since otl2html doesn't play nice with buffering.
|
|
|
|
# Instead, fork off a child process that will run otl2html and feed
|
|
|
|
# it the content. Then read otl2html's response.
|
|
|
|
|
2006-08-18 23:48:03 +02:00
|
|
|
my $tries=10;
|
2006-09-03 22:11:39 +02:00
|
|
|
my $pid;
|
2006-09-08 22:33:49 +02:00
|
|
|
do {
|
|
|
|
$pid = open(KID_TO_READ, "-|");
|
|
|
|
unless (defined $pid) {
|
|
|
|
$tries--;
|
|
|
|
if ($tries < 1) {
|
2006-09-10 00:50:27 +02:00
|
|
|
debug("failed to fork: $@");
|
2006-09-08 22:33:49 +02:00
|
|
|
return $params{content};
|
|
|
|
}
|
2006-08-18 23:48:03 +02:00
|
|
|
}
|
2006-09-08 22:33:49 +02:00
|
|
|
} until defined $pid;
|
|
|
|
|
|
|
|
if (! $pid) {
|
|
|
|
$tries=10;
|
|
|
|
$pid=undef;
|
|
|
|
|
|
|
|
do {
|
|
|
|
$pid = open(KID_TO_WRITE, "|-");
|
|
|
|
unless (defined $pid) {
|
|
|
|
$tries--;
|
|
|
|
if ($tries < 1) {
|
2006-09-10 00:50:27 +02:00
|
|
|
debug("failed to fork: $@");
|
2006-09-08 22:33:49 +02:00
|
|
|
print $params{content};
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} until defined $pid;
|
|
|
|
|
|
|
|
if (! $pid) {
|
|
|
|
if (! exec 'otl2html', '-S', '/dev/null', '-T', '/dev/stdin') {
|
2006-09-10 00:50:27 +02:00
|
|
|
debug("failed to run otl2html: $@");
|
2006-09-08 22:33:49 +02:00
|
|
|
print $params{content};
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print KID_TO_WRITE $params{content};
|
|
|
|
close KID_TO_WRITE;
|
|
|
|
waitpid $pid, 0;
|
|
|
|
exit;
|
2006-08-18 23:48:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
local $/ = undef;
|
2006-09-08 22:33:49 +02:00
|
|
|
my $ret=<KID_TO_READ>;
|
|
|
|
close KID_TO_READ;
|
2006-09-03 22:11:39 +02:00
|
|
|
waitpid $pid, 0;
|
|
|
|
|
2006-08-18 23:48:03 +02:00
|
|
|
$ret=~s/.*<body>//s;
|
|
|
|
$ret=~s/<body>.*//s;
|
2006-08-19 05:06:32 +02:00
|
|
|
$ret=~s/<div class="Footer">.*//s;
|
2006-08-18 23:48:03 +02:00
|
|
|
return $ret;
|
2008-12-17 21:22:16 +01:00
|
|
|
}
|
2006-08-18 23:48:03 +02:00
|
|
|
|
|
|
|
1
|