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)))));
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
call => \&sanitize);
} # }}}
-sub sanitize ($) { #{{{
- return scrubber()->scrub(shift);
+sub sanitize (@) { #{{{
+ my %params=@_;
+ return scrubber()->scrub($params{content});
} # }}}
my $_scrubber;
IkiWiki::hook(type => "sanitize", id => "tidy", call => \&sanitize);
} # }}}
-sub sanitize ($) { #{{{
+sub sanitize (@) { #{{{
+ my %params=@_;
+
my $tries=10;
while (1) {
eval {
$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;
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,
} # }}}
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
return $params{content};
} # }}}
-sub htmlize ($) { #{{{
+sub htmlize (@) { #{{{
+ my %params=@_;
+
my $tries=10;
while (1) {
eval {
$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;
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) {
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))));
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 (@) { #{{{
call => \&format);
} # }}}
-my @tocs;
+my %tocpages;
sub preprocess (@) { #{{{
my %params=@_;
# 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="";
$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;
}
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 });
} # }}}
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;
$content=$template->output;
run_hooks(format => sub {
- $content=shift->($content);
+ $content=shift->(
+ page => $page,
+ content => $content,
+ );
});
return $content;
$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},
"<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
* 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
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);
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
%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;
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");