X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/21add7ffa87a5e622d18bdbb24c638c15bdb3800..dad25308d2832de28d3b8151aacc3b124575733c:/IkiWiki/Plugin/format.pm diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm index b4d3a3c5f..1513cbed7 100644 --- a/IkiWiki/Plugin/format.pm +++ b/IkiWiki/Plugin/format.pm @@ -3,28 +3,40 @@ package IkiWiki::Plugin::format; use warnings; use strict; -use IkiWiki 2.00; +use IkiWiki 3.00; sub import { hook(type => "preprocess", id => "format", call => \&preprocess); } 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}) { - 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, - IkiWiki::preprocess($params{page}, $params{destpage}, $text)); + error(sprintf(gettext("unsupported page format %s"), $format)); + } } 1