X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/bb841f94f47d865e4c78bd4f27c5f9cc04dc1557..1334695f4ca8a08ea94c176f5cc4c1fafa7aa31c:/IkiWiki/Plugin/format.pm?ds=inline diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index a219190e8..d54e71131 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -3,27 +3,50 @@ package IkiWiki::Plugin::format; 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 => "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 $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")); } - elsif (! exists $IkiWiki::hooks{htmlize}{$format}) { - error(sprintf(gettext("unsupported page format %s"), $format)); + elsif (exists $IkiWiki::hooks{htmlize}{$format}) { + return IkiWiki::htmlize($params{page}, $params{destpage}, + $format, $text); } + else { + # Other plugins can register htmlizefallback + # hooks to add support for page types + # not suitable for htmlize. Try them until + # one succeeds. + my $ret; + IkiWiki::run_hooks(htmlizefallback => sub { + $ret=shift->($format, $text) + unless defined $ret; + }); + return $ret if defined $ret; - return IkiWiki::htmlize($params{page}, $params{destpage}, $format, $text); -} #}}} + error(sprintf(gettext("unsupported page format %s"), $format)); + } +} 1