X-Git-Url: http://git.vanrenterghem.biz/git.ikiwiki.info.git/blobdiff_plain/6f1539320b7b2701d391c9921177b31898767bb7..e5f88c384e9ae6b071436af9da14ce1eb621fdeb:/IkiWiki/Plugin/format.pm diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index bbe3aa9fe..b596bc0a1 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -7,24 +7,48 @@ use IkiWiki 3.00; sub import { hook(type => "preprocess", id => "format", call => \&preprocess); + hook(type => "getsetup", id => "format", call => \&getsetup); +} + +sub getsetup () { + return + plugin => { + safe => 1, + rebuild => undef, + section => "widget", + }, } sub preprocess (@) { - my $format=$_[0]; - shift; shift; - my $text=$_[0]; - shift; shift; 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}) { + + # 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)); } - - return IkiWiki::htmlize($params{page}, $params{destpage}, $format, - IkiWiki::preprocess($params{page}, $params{destpage}, $text)); } 1