* Change htmlize, format, and sanitize hooks to use named parameters.
parent
e3a6ff0044
commit
4895955cea
|
@ -425,7 +425,7 @@ sub cgi_editpage ($$) { #{{{
|
|||
value => $comments, force => 1);
|
||||
$config{rss}=0; # avoid preview writing an rss feed!
|
||||
$form->tmpl_param("page_preview",
|
||||
htmlize($type,
|
||||
htmlize($page, $type,
|
||||
linkify($page, "",
|
||||
preprocess($page, $page,
|
||||
filter($page, $content)))));
|
||||
|
|
|
@ -7,12 +7,17 @@ use strict;
|
|||
use IkiWiki;
|
||||
|
||||
sub import { #{{{
|
||||
IkiWiki::hook(type => "htmlize", id => "html", call => sub { shift });
|
||||
IkiWiki::hook(type => "htmlize", id => "htm", call => sub { shift });
|
||||
IkiWiki::hook(type => "htmlize", id => "html", call => \&htmlize);
|
||||
IkiWiki::hook(type => "htmlize", id => "htm", call => \&htmlize);
|
||||
|
||||
# ikiwiki defaults to skipping .html files as a security measure;
|
||||
# make it process them so this plugin can take effect
|
||||
$IkiWiki::config{wiki_file_prune_regexp} =~ s/\|\\\.x\?html\?\$//;
|
||||
} # }}}
|
||||
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
return $params{content};
|
||||
} #}}}
|
||||
|
||||
1
|
||||
|
|
|
@ -10,8 +10,9 @@ sub import { #{{{
|
|||
call => \&sanitize);
|
||||
} # }}}
|
||||
|
||||
sub sanitize ($) { #{{{
|
||||
return scrubber()->scrub(shift);
|
||||
sub sanitize (@) { #{{{
|
||||
my %params=@_;
|
||||
return scrubber()->scrub($params{content});
|
||||
} # }}}
|
||||
|
||||
my $_scrubber;
|
||||
|
|
|
@ -16,7 +16,9 @@ sub import { #{{{
|
|||
IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
|
||||
} # }}}
|
||||
|
||||
sub sanitize ($) { #{{{
|
||||
sub sanitize (@) { #{{{
|
||||
my %params=@_;
|
||||
|
||||
my $tries=10;
|
||||
while (1) {
|
||||
eval {
|
||||
|
@ -26,14 +28,14 @@ sub sanitize ($) { #{{{
|
|||
$tries--;
|
||||
if ($tries < 1) {
|
||||
IkiWiki::debug("failed to run tidy: $@");
|
||||
return shift;
|
||||
return $params{content};
|
||||
}
|
||||
}
|
||||
# open2 doesn't respect "use open ':utf8'"
|
||||
binmode (IN, ':utf8');
|
||||
binmode (OUT, ':utf8');
|
||||
|
||||
print OUT shift;
|
||||
print OUT $params{content};
|
||||
close OUT;
|
||||
|
||||
local $/ = undef;
|
||||
|
|
|
@ -144,7 +144,7 @@ sub get_inline_content ($$) { #{{{
|
|||
my $file=$pagesources{$page};
|
||||
my $type=pagetype($file);
|
||||
if (defined $type) {
|
||||
return htmlize($type,
|
||||
return htmlize($page, $type,
|
||||
linkify($page, $destpage,
|
||||
preprocess($page, $destpage,
|
||||
filter($page,
|
||||
|
|
|
@ -11,8 +11,9 @@ sub import { #{{{
|
|||
} # }}}
|
||||
|
||||
my $markdown_loaded=0;
|
||||
sub htmlize ($) { #{{{
|
||||
my $content = shift;
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
my $content = $params{content};
|
||||
|
||||
if (! $markdown_loaded) {
|
||||
# Note: This hack to make markdown run as a proper perl
|
||||
|
|
|
@ -27,7 +27,9 @@ sub filter (@) { #{{{
|
|||
return $params{content};
|
||||
} # }}}
|
||||
|
||||
sub htmlize ($) { #{{{
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
|
||||
my $tries=10;
|
||||
while (1) {
|
||||
eval {
|
||||
|
@ -37,14 +39,14 @@ sub htmlize ($) { #{{{
|
|||
$tries--;
|
||||
if ($tries < 1) {
|
||||
IkiWiki::debug("failed to run otl2html: $@");
|
||||
return shift;
|
||||
return $params{content};
|
||||
}
|
||||
}
|
||||
# open2 doesn't respect "use open ':utf8'"
|
||||
binmode (IN, ':utf8');
|
||||
binmode (OUT, ':utf8');
|
||||
|
||||
print OUT shift;
|
||||
print OUT $params{content};
|
||||
close OUT;
|
||||
|
||||
local $/ = undef;
|
||||
|
|
|
@ -39,8 +39,9 @@ sub import { #{{{
|
|||
IkiWiki::hook(type => "htmlize", id => "rst", call => \&htmlize);
|
||||
} # }}}
|
||||
|
||||
sub htmlize ($) { #{{{
|
||||
my $content=shift;
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
my $content=$params{content};
|
||||
|
||||
my $tries=10;
|
||||
while (1) {
|
||||
|
|
|
@ -28,7 +28,7 @@ sub sidebar_content ($) { #{{{
|
|||
|
||||
my $content=IkiWiki::readfile(IkiWiki::srcfile($sidebar_file));
|
||||
return unless length $content;
|
||||
return IkiWiki::htmlize($sidebar_type,
|
||||
return IkiWiki::htmlize($page, $sidebar_type,
|
||||
IkiWiki::linkify($sidebar_page, $page,
|
||||
IkiWiki::preprocess($sidebar_page, $page,
|
||||
IkiWiki::filter($sidebar_page, $content))));
|
||||
|
|
|
@ -57,28 +57,28 @@ sub filter (@) { #{{{
|
|||
return $params{content};
|
||||
} # }}}
|
||||
|
||||
sub htmlize ($) { #{{{
|
||||
my $content=shift;
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
|
||||
IkiWiki::debug("skeleton plugin running as htmlize");
|
||||
|
||||
return $content;
|
||||
return $params{content};
|
||||
} # }}}
|
||||
|
||||
sub sanitize ($) { #{{{
|
||||
my $content=shift;
|
||||
sub sanitize (@) { #{{{
|
||||
my %params=@_;
|
||||
|
||||
IkiWiki::debug("skeleton plugin running as a sanitizer");
|
||||
|
||||
return $content;
|
||||
return $params{content};
|
||||
} # }}}
|
||||
|
||||
sub format ($) { #{{{
|
||||
my $content=shift;
|
||||
sub format (@) { #{{{
|
||||
my %params=@_;
|
||||
|
||||
IkiWiki::debug("skeleton plugin running as a formatter");
|
||||
|
||||
return $content;
|
||||
return $params{content};
|
||||
} # }}}
|
||||
|
||||
sub pagetemplate (@) { #{{{
|
||||
|
|
|
@ -14,7 +14,7 @@ sub import { #{{{
|
|||
call => \&format);
|
||||
} # }}}
|
||||
|
||||
my @tocs;
|
||||
my %tocpages;
|
||||
|
||||
sub preprocess (@) { #{{{
|
||||
my %params=@_;
|
||||
|
@ -23,17 +23,17 @@ sub preprocess (@) { #{{{
|
|||
|
||||
# It's too early to generate the toc here, so just record the
|
||||
# info.
|
||||
push @tocs, \%params;
|
||||
$tocpages{$params{destpage}}=\%params;
|
||||
|
||||
return "\n[[toc $#tocs]]\n";
|
||||
return "\n<div class=\"toc\"></div>\n";
|
||||
} # }}}
|
||||
|
||||
sub format ($) { #{{{
|
||||
my $content=shift;
|
||||
sub format (@) { #{{{
|
||||
my %params=@_;
|
||||
my $content=$params{content};
|
||||
|
||||
return $content unless @tocs && $content=~/\[\[toc (\d+)\]\]/ && $#tocs >= $1;
|
||||
my $id=$1;
|
||||
my %params=%{$tocs[$id]};
|
||||
return $content unless exists $tocpages{$params{page}};
|
||||
%params=%{$tocpages{$params{page}}};
|
||||
|
||||
my $p=HTML::Parser->new(api_version => 3);
|
||||
my $page="";
|
||||
|
@ -107,9 +107,7 @@ sub format ($) { #{{{
|
|||
$index.=&$indent."</ol>\n";
|
||||
}
|
||||
|
||||
# Ignore cruft around the toc marker, probably <p> tags added by
|
||||
# markdown which shouldn't appear in a list anyway.
|
||||
$page=~s/\n.*\[\[toc $id\]\].*\n/$index/;
|
||||
$page=~s/(<div class=\"toc\">)/$1\n$index/;
|
||||
return $page;
|
||||
}
|
||||
|
||||
|
|
|
@ -11,8 +11,9 @@ sub import { #{{{
|
|||
IkiWiki::hook(type => "htmlize", id => "wiki", call => \&htmlize);
|
||||
} # }}}
|
||||
|
||||
sub htmlize ($) { #{{{
|
||||
my $content = shift;
|
||||
sub htmlize (@) { #{{{
|
||||
my %params=@_;
|
||||
my $content = $params{content};
|
||||
|
||||
return Text::WikiFormat::format($content, undef, { implicit_links => 0 });
|
||||
} # }}}
|
||||
|
|
|
@ -20,19 +20,26 @@ sub linkify ($$$) { #{{{
|
|||
return $content;
|
||||
} #}}}
|
||||
|
||||
sub htmlize ($$) { #{{{
|
||||
sub htmlize ($$$) { #{{{
|
||||
my $page=shift;
|
||||
my $type=shift;
|
||||
my $content=shift;
|
||||
|
||||
if (exists $hooks{htmlize}{$type}) {
|
||||
$content=$hooks{htmlize}{$type}{call}->($content);
|
||||
$content=$hooks{htmlize}{$type}{call}->(
|
||||
page => $page,
|
||||
content => $content,
|
||||
);
|
||||
}
|
||||
else {
|
||||
error("htmlization of $type not supported");
|
||||
}
|
||||
|
||||
run_hooks(sanitize => sub {
|
||||
$content=shift->($content);
|
||||
$content=shift->(
|
||||
page => $page,
|
||||
content => $content,
|
||||
);
|
||||
});
|
||||
|
||||
return $content;
|
||||
|
@ -209,7 +216,10 @@ sub genpage ($$$) { #{{{
|
|||
$content=$template->output;
|
||||
|
||||
run_hooks(format => sub {
|
||||
$content=shift->($content);
|
||||
$content=shift->(
|
||||
page => $page,
|
||||
content => $content,
|
||||
);
|
||||
});
|
||||
|
||||
return $content;
|
||||
|
@ -287,7 +297,7 @@ sub render ($) { #{{{
|
|||
|
||||
$content=preprocess($page, $page, $content);
|
||||
$content=linkify($page, $page, $content);
|
||||
$content=htmlize($type, $content);
|
||||
$content=htmlize($page, $type, $content);
|
||||
|
||||
check_overwrite("$config{destdir}/".htmlpage($page), $page);
|
||||
writefile(htmlpage($page), $config{destdir},
|
||||
|
|
|
@ -5,6 +5,11 @@ ikiwiki (1.22) unstable; urgency=low
|
|||
"<TMPL_VAR BASEURL>style.css" instead of the old method which used
|
||||
STYLEURL.
|
||||
|
||||
There have also been some changes to the plugin interface:
|
||||
Any plugins that use santize, htmlize, or format hooks will need to be
|
||||
updated for this version of ikiwiki since these hooks have been changed
|
||||
to use named parameters.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Tue, 22 Aug 2006 15:33:12 -0400
|
||||
|
||||
ikiwiki (1.13) unstable; urgency=low
|
||||
|
|
|
@ -41,8 +41,9 @@ ikiwiki (1.22) UNRELEASED; urgency=low
|
|||
* Fix preferences page on anonok wikis; still need to sign in to get
|
||||
to the preferences page.
|
||||
* Add toc (table of contents) plugin.
|
||||
* Change htmlize, format, and sanitize hooks to use named parameters.
|
||||
|
||||
-- Joey Hess <joeyh@debian.org> Mon, 28 Aug 2006 02:31:56 -0400
|
||||
-- Joey Hess <joeyh@debian.org> Mon, 28 Aug 2006 13:59:29 -0400
|
||||
|
||||
ikiwiki (1.21) unstable; urgency=low
|
||||
|
||||
|
|
|
@ -94,6 +94,9 @@ specifies the filename extension that a file must have to be htmlized using
|
|||
this plugin. This is how you can add support for new and exciting markup
|
||||
languages to ikiwiki.
|
||||
|
||||
The function is passed named parameters: "page" and "content" and should
|
||||
return the htmlized content.
|
||||
|
||||
## pagetemplate
|
||||
|
||||
IkiWiki::hook(type => "pagetemplate", id => "foo", call => \&pagetemplate);
|
||||
|
@ -115,18 +118,20 @@ a new custom parameter to the template.
|
|||
|
||||
Use this to implement html sanitization or anything else that needs to
|
||||
modify the body of a page after it has been fully converted to html.
|
||||
The function is passed the page content and should return the sanitized
|
||||
content.
|
||||
|
||||
The function is passed named parameters: "page" and "content", and
|
||||
should return the sanitized content.
|
||||
|
||||
## format
|
||||
|
||||
IkiWiki::hook(type => "format", id => "foo", call => \&format);
|
||||
|
||||
The function is passed the complete page content and can reformat it
|
||||
and return the new content. The difference between format and sanitize is
|
||||
that sanitize only acts on the page body, while format can modify the
|
||||
entire html page including the header and footer inserted by ikiwiki, the
|
||||
html document type, etc.
|
||||
The difference between format and sanitize is that sanitize only acts on
|
||||
the page body, while format can modify the entire html page including the
|
||||
header and footer inserted by ikiwiki, the html document type, etc.
|
||||
|
||||
The function is passed named parameters: "page" and "content", and
|
||||
should return the formatted content.
|
||||
|
||||
## delete
|
||||
|
||||
|
|
|
@ -14,6 +14,6 @@ BEGIN { use_ok("IkiWiki::Render"); }
|
|||
%IkiWiki::config=IkiWiki::defaultconfig();
|
||||
$IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
|
||||
IkiWiki::loadplugins(); IkiWiki::checkconfig();
|
||||
ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test1.mdwn")));
|
||||
ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test3.mdwn")),
|
||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test1.mdwn")));
|
||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test3.mdwn")),
|
||||
"wtf?") for 1..100;
|
||||
|
|
|
@ -13,10 +13,10 @@ $IkiWiki::config{srcdir}=$IkiWiki::config{destdir}="/dev/null";
|
|||
IkiWiki::loadplugins();
|
||||
IkiWiki::checkconfig();
|
||||
|
||||
is(IkiWiki::htmlize("mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
|
||||
is(IkiWiki::htmlize("foo", "mdwn", "foo\n\nbar\n"), "<p>foo</p>\n\n<p>bar</p>\n",
|
||||
"basic");
|
||||
is(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test1.mdwn")),
|
||||
is(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test1.mdwn")),
|
||||
Encode::decode_utf8(qq{<p><img src="../images/o.jpg" alt="o" title="ó" />\nóóóóó</p>\n}),
|
||||
"utf8; bug #373203");
|
||||
ok(IkiWiki::htmlize("mdwn", IkiWiki::readfile("t/test2.mdwn")),
|
||||
ok(IkiWiki::htmlize("foo", "mdwn", IkiWiki::readfile("t/test2.mdwn")),
|
||||
"this file crashes markdown if it's fed in as decoded utf-8");
|
||||
|
|
Loading…
Reference in New Issue