aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Plugin/highlight.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/highlight.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/highlight.pm')
-rw-r--r--IkiWiki/Plugin/highlight.pm21
1 files changed, 20 insertions, 1 deletions
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>