summaryrefslogtreecommitdiff
path: root/IkiWiki
diff options
context:
space:
mode:
Diffstat (limited to 'IkiWiki')
-rw-r--r--IkiWiki/Plugin/format.pm28
-rw-r--r--IkiWiki/Plugin/highlight.pm21
2 files changed, 40 insertions, 9 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
diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm
index 117ab5898..f116c41dd 100644
--- a/IkiWiki/Plugin/highlight.pm
+++ b/IkiWiki/Plugin/highlight.pm
@@ -4,7 +4,6 @@ package IkiWiki::Plugin::highlight;
use warnings;
use strict;
use IkiWiki 3.00;
-use highlight;
# locations of highlight's files
my $filetypes="/etc/highlight/filetypes.conf";
@@ -13,6 +12,9 @@ my $langdefdir="/usr/share/highlight/langDefs";
sub import {
hook(type => "getsetup", id => "highlight", call => \&getsetup);
hook(type => "checkconfig", id => "highlight", call => \&checkconfig);
+ # this hook is used by the format plugin
+ hook(type => "htmlizefallback", id => "highlight", call =>
+ \&htmlizefallback);
}
sub getsetup () {
@@ -59,6 +61,17 @@ sub checkconfig () {
}
}
+sub htmlizefallback {
+ my $format=lc shift;
+ my $langfile=ext2langfile($format);
+
+ if (! defined $langfile) {
+ return;
+ }
+
+ return highlight($langfile, shift);
+}
+
my %ext2lang;
my $filetypes_read=0;
@@ -103,6 +116,12 @@ sub highlight ($$) {
my $langfile=shift;
my $input=shift;
+ eval q{use highlight};
+ if ($@) {
+ print STDERR gettext("warning: highlight perl module not available; falling back to pass through");
+ return $input;
+ }
+
my $gen = highlightc::CodeGenerator_getInstance($highlightc::XHTML);
$gen->setFragmentCode(1); # generate html fragment
$gen->setHTMLEnclosePreTag(1); # include stylish <pre>