summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--IkiWiki/CGI.pm2
-rw-r--r--IkiWiki/Plugin/html.pm9
-rw-r--r--IkiWiki/Plugin/htmlscrubber.pm5
-rw-r--r--IkiWiki/Plugin/htmltidy.pm8
-rw-r--r--IkiWiki/Plugin/inline.pm2
-rw-r--r--IkiWiki/Plugin/mdwn.pm5
-rw-r--r--IkiWiki/Plugin/otl.pm8
-rw-r--r--IkiWiki/Plugin/rst.pm5
-rw-r--r--IkiWiki/Plugin/sidebar.pm2
-rw-r--r--IkiWiki/Plugin/skeleton.pm18
-rw-r--r--IkiWiki/Plugin/toc.pm20
-rw-r--r--IkiWiki/Plugin/wikitext.pm5
-rw-r--r--IkiWiki/Render.pm20
-rw-r--r--debian/NEWS5
-rw-r--r--debian/changelog3
-rw-r--r--doc/plugins/write.mdwn19
-rwxr-xr-xt/crazy-badass-perl-bug.t4
-rwxr-xr-xt/htmlize.t6
18 files changed, 89 insertions, 57 deletions
diff --git a/IkiWiki/CGI.pm b/IkiWiki/CGI.pm
index 8e0339dc5..99fc5c0ed 100644
--- a/IkiWiki/CGI.pm
+++ b/IkiWiki/CGI.pm
@@ -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)))));
diff --git a/IkiWiki/Plugin/html.pm b/IkiWiki/Plugin/html.pm
index 8d3187a71..83720b4b5 100644
--- a/IkiWiki/Plugin/html.pm
+++ b/IkiWiki/Plugin/html.pm
@@ -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
diff --git a/IkiWiki/Plugin/htmlscrubber.pm b/IkiWiki/Plugin/htmlscrubber.pm
index 8e8391817..d77ab809b 100644
--- a/IkiWiki/Plugin/htmlscrubber.pm
+++ b/IkiWiki/Plugin/htmlscrubber.pm
@@ -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;
diff --git a/IkiWiki/Plugin/htmltidy.pm b/IkiWiki/Plugin/htmltidy.pm
index eb8f9d3d3..079da7b49 100644
--- a/IkiWiki/Plugin/htmltidy.pm
+++ b/IkiWiki/Plugin/htmltidy.pm
@@ -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;
diff --git a/IkiWiki/Plugin/inline.pm b/IkiWiki/Plugin/inline.pm
index fe7dde14c..1cbde7104 100644
--- a/IkiWiki/Plugin/inline.pm
+++ b/IkiWiki/Plugin/inline.pm
@@ -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,
diff --git a/IkiWiki/Plugin/mdwn.pm b/IkiWiki/Plugin/mdwn.pm
index 8e037f5de..2274fea72 100644
--- a/IkiWiki/Plugin/mdwn.pm
+++ b/IkiWiki/Plugin/mdwn.pm
@@ -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
diff --git a/IkiWiki/Plugin/otl.pm b/IkiWiki/Plugin/otl.pm
index 314ed28ad..be339c88e 100644
--- a/IkiWiki/Plugin/otl.pm
+++ b/IkiWiki/Plugin/otl.pm
@@ -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;
diff --git a/IkiWiki/Plugin/rst.pm b/IkiWiki/Plugin/rst.pm
index 6bf11fe36..08ac15e43 100644
--- a/IkiWiki/Plugin/rst.pm
+++ b/IkiWiki/Plugin/rst.pm
@@ -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) {
diff --git a/IkiWiki/Plugin/sidebar.pm b/IkiWiki/Plugin/sidebar.pm
index e0e81526f..0b006f110 100644
--- a/IkiWiki/Plugin/sidebar.pm
+++ b/IkiWiki/Plugin/sidebar.pm
@@ -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))));
diff --git a/IkiWiki/Plugin/skeleton.pm b/IkiWiki/Plugin/skeleton.pm
index 4683b00ba..5947ebb4c 100644
--- a/IkiWiki/Plugin/skeleton.pm
+++ b/IkiWiki/Plugin/skeleton.pm
@@ -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 (@) { #{{{
diff --git a/IkiWiki/Plugin/toc.pm b/IkiWiki/Plugin/toc.pm
index c36ce2893..063e66f3b 100644
--- a/IkiWiki/Plugin/toc.pm
+++ b/IkiWiki/Plugin/toc.pm
@@ -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;
}
diff --git a/IkiWiki/Plugin/wikitext.pm b/IkiWiki/Plugin/wikitext.pm
index 9fa87dafb..5c46c565c 100644
--- a/IkiWiki/Plugin/wikitext.pm
+++ b/IkiWiki/Plugin/wikitext.pm
@@ -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 });
} # }}}
diff --git a/IkiWiki/Render.pm b/IkiWiki/Render.pm
index 58556148f..ca6e9666b 100644
--- a/IkiWiki/Render.pm
+++ b/IkiWiki/Render.pm
@@ -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},
diff --git a/debian/NEWS b/debian/NEWS
index bb52741e7..3222ec69e 100644
--- a/debian/NEWS
+++ b/debian/NEWS
@@ -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
diff --git a/debian/changelog b/debian/changelog
index ccff36c9a..f105582a4 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -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
diff --git a/doc/plugins/write.mdwn b/doc/plugins/write.mdwn
index af970221e..bfa0bad1d 100644
--- a/doc/plugins/write.mdwn
+++ b/doc/plugins/write.mdwn
@@ -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
diff --git a/t/crazy-badass-perl-bug.t b/t/crazy-badass-perl-bug.t
index 047ff1db2..78f0b5011 100755
--- a/t/crazy-badass-perl-bug.t
+++ b/t/crazy-badass-perl-bug.t
@@ -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;
diff --git a/t/htmlize.t b/t/htmlize.t
index 070fbf958..fc9ca5b84 100755
--- a/t/htmlize.t
+++ b/t/htmlize.t
@@ -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="&oacute;" />\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");