]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/format.pm
allow format to use any language supported by highlight
[ikiwiki.git] / IkiWiki / Plugin / format.pm
index bbe3aa9fee56e28b978e8d11c0f5f71d6d1b8824..1513cbed72a67447fa8bcedd9bff1f10ce076262 100644 (file)
@@ -10,21 +10,33 @@ sub import {
 }
 
 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