]> sipb.mit.edu Git - ikiwiki.git/commitdiff
* Change htmlize, format, and sanitize hooks to use named parameters.
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 28 Aug 2006 18:17:59 +0000 (18:17 +0000)
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>
Mon, 28 Aug 2006 18:17:59 +0000 (18:17 +0000)
18 files changed:
IkiWiki/CGI.pm
IkiWiki/Plugin/html.pm
IkiWiki/Plugin/htmlscrubber.pm
IkiWiki/Plugin/htmltidy.pm
IkiWiki/Plugin/inline.pm
IkiWiki/Plugin/mdwn.pm
IkiWiki/Plugin/otl.pm
IkiWiki/Plugin/rst.pm
IkiWiki/Plugin/sidebar.pm
IkiWiki/Plugin/skeleton.pm
IkiWiki/Plugin/toc.pm
IkiWiki/Plugin/wikitext.pm
IkiWiki/Render.pm
debian/NEWS
debian/changelog
doc/plugins/write.mdwn
t/crazy-badass-perl-bug.t
t/htmlize.t

index 8e0339dc5436097e1727390076903fe3933171a5..99fc5c0edf71af55e0288bf5b7b14147832aa1b6 100644 (file)
@@ -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)))));
index 8d3187a71f50ffbf33152fed8999b3802d7df4f5..83720b4b59c84e5b317f46e77e4ca9e82b29a02e 100644 (file)
@@ -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
index 8e83918170b3b8f4d11a0fed369675338eedcaca..d77ab809b7f67ae0e7d3d86842e12ea06a00736b 100644 (file)
@@ -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;
index eb8f9d3d37efb4037d53ee7a23bcae168a5b8826..079da7b493d29d84b6ffdba6d4d06f0498ec88ec 100644 (file)
@@ -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;
index fe7dde14cfbec98c30d0a30c6696868486083c51..1cbde71045c51d761a30de8f4cdedb4bbb5f323f 100644 (file)
@@ -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,
index 8e037f5de192377018cd81c8f12a10c89d76d9bf..2274fea72489b3256cd3d05ee9b0ba7f0dd82d42 100644 (file)
@@ -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
index 314ed28ad07061a90a110257800c81f5a46906d3..be339c88ebee44b77371422822ae4816a102cd5e 100644 (file)
@@ -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;
index 6bf11fe36561c516d1bd10b6e58af34396157df5..08ac15e43fb419b05e2a5d718c266b44c7bb4a50 100644 (file)
@@ -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) {
index e0e81526f080cdb502d0f72cfb8e4e4bf145303a..0b006f110b20a963bba9b4acc575db1c95e9fcce 100644 (file)
@@ -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))));
index 4683b00ba707a51809001dd3baa79f6068a1bf3c..5947ebb4c2fdc974dfa852ddb1add9b628a0e2d5 100644 (file)
@@ -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 (@) { #{{{
index c36ce289368c945eff3f3e94164bfc004e2b5235..063e66f3babafaa674bcd9a3d5ef472dfd2e4f20 100644 (file)
@@ -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;
 }
 
index 9fa87dafb1c06902bdcc58e230f7c53f2325fe94..5c46c565cc7b95100c3124fa9a3c496bb4afc502 100644 (file)
@@ -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 });
 } # }}}
index 58556148f21fa216f04aaa3a827794384e6db2d7..ca6e9666bfb345c57c6da8e8757ea024eeee7018 100644 (file)
@@ -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},
index bb52741e73be855960151e55c52503265f94a04e..3222ec69e7ea6c02f4b7e5b647889f66b582dc19 100644 (file)
@@ -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
index ccff36c9a3fd9f52c4f5e926aacdf8f18e4edb78..f105582a4f926a87464a909296ebb1e84f1e0327 100644 (file)
@@ -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
 
index af970221e38bb3b0aade201aa9cd7d0df6b600f1..bfa0bad1d27378d8af9dd5295feb6e12e170590f 100644 (file)
@@ -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
 
index 047ff1db2499305aa906f14de30b5c896d569ef8..78f0b50112885d44e490925270058620f705c477 100755 (executable)
@@ -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;
index 070fbf9584740a1f5b65e37c40e0a79c9bb5ad69..fc9ca5b84ec64b03b6c61ad55201c7ab34b4303e 100755 (executable)
@@ -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");