aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/format.pm
diff options
context:
space:
mode:
authorJoey Hess <joey@gnu.kitenet.net>2009-05-23 05:17:26 -0400
committerJoey Hess <joey@gnu.kitenet.net>2009-05-23 05:17:26 -0400
commit47298b01c1921deff7e056406245a90f8371bd59 (patch)
tree60d783b258d444c122120abc5821d0ba6b9ccb2c /IkiWiki/Plugin/format.pm
parentcdd1b58b386da575f3c73ab94ae72e5e66be797b (diff)
downloadikiwiki-47298b01c1921deff7e056406245a90f8371bd59.tar
ikiwiki-47298b01c1921deff7e056406245a90f8371bd59.tar.gz
allow format to use any language supported by highlight
format: Provide a htmlizefallback hook that other plugins can use to handle formats that are not suitable for general-purpose htmlize hooks. highlight: Use the hook to allow formatting of any language/extension, without it needing to be enabled for standalone source files. highlight: If the highlight perl binding is not available, fallback safely to a passthrough mode.
Diffstat (limited to 'IkiWiki/Plugin/format.pm')
-rw-r--r--IkiWiki/Plugin/format.pm28
1 files changed, 20 insertions, 8 deletions
diff --git a/IkiWiki/Plugin/format.pm b/IkiWiki/Plugin/format.pm
index bbe3aa9fe..1513cbed7 100644
--- a/IkiWiki/Plugin/format.pm
+++ b/IkiWiki/Plugin/format.pm
@@ -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