]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/format.pm
Provide a UUID in edittemplate templates.
[ikiwiki.git] / IkiWiki / Plugin / format.pm
index 1e21a0bdc59d01b1768e04a812b6fd59e4afb7b1..b596bc0a10343b91cf7287f5b5fa06a81084b055 100644 (file)
@@ -3,28 +3,52 @@ package IkiWiki::Plugin::format;
 
 use warnings;
 use strict;
 
 use warnings;
 use strict;
-use IkiWiki 2.00;
+use IkiWiki 3.00;
 
 
-sub import { #{{{
+sub import {
        hook(type => "preprocess", id => "format", call => \&preprocess);
        hook(type => "preprocess", id => "format", call => \&preprocess);
-} #}}}
+       hook(type => "getsetup",   id => "format", call => \&getsetup);
+}
 
 
-sub preprocess (@) { #{{{
-       my $format=$_[0];
-       shift; shift;
-       my $text=$_[0];
-       shift; shift;
+sub getsetup () {
+       return
+               plugin => {
+                       safe => 1,
+                       rebuild => undef,
+                       section => "widget",
+               },
+}
+
+sub preprocess (@) {
        my %params=@_;
        my %params=@_;
+       my $format=shift;
+       shift;
+       my $text=IkiWiki::preprocess($params{page}, $params{destpage}, shift);
+       shift;
 
        if (! defined $format || ! defined $text) {
                error(gettext("must specify format and text"));
        }
 
        if (! defined $format || ! defined $text) {
                error(gettext("must specify format and text"));
        }
-       elsif (! exists $IkiWiki::hooks{htmlize}{$format}) {
+               
+       # Other plugins can register htmlizeformat hooks to add support
+       # for page types not suitable for htmlize, or that need special
+       # processing when included via format. Try them until one succeeds.
+       my $ret;
+       IkiWiki::run_hooks(htmlizeformat => sub {
+               $ret=shift->($format, $text)
+                       unless defined $ret;
+       });
+
+       if (defined $ret) {
+               return $ret;
+       }
+       elsif (exists $IkiWiki::hooks{htmlize}{$format}) {
+               return IkiWiki::htmlize($params{page}, $params{destpage},
+                                       $format, $text);
+       }
+       else {
                error(sprintf(gettext("unsupported page format %s"), $format));
        }
                error(sprintf(gettext("unsupported page format %s"), $format));
        }
-
-       return IkiWiki::htmlize($params{page}, $params{destpage}, $format,
-               IkiWiki::preprocess($params{page}, $params{destpage}, $text));
-} #}}}
+}
 
 1
 
 1