X-Git-Url: https://scripts.mit.edu/gitweb/www/ikiwiki.git/blobdiff_plain/931036eb5c2a26dd0f4bae1c6d9003b65ad890ff..93d77673e44c1c4019a2fcbae2e450f095c4426a:/IkiWiki/Plugin/highlight.pm diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm index d4ade0a7b..9d05e9fcf 100644 --- a/IkiWiki/Plugin/highlight.pm +++ b/IkiWiki/Plugin/highlight.pm @@ -10,8 +10,8 @@ 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); + hook(type => "htmlizeformat", id => "highlight", + call => \&htmlizeformat, last => 1); } sub getsetup () { @@ -79,7 +79,7 @@ sub checkconfig () { } } -sub htmlizefallback { +sub htmlizeformat { my $format=lc shift; my $langfile=ext2langfile($format); @@ -96,14 +96,29 @@ my %highlighters; # Parse highlight's config file to get extension => language mappings. sub read_filetypes () { - open (IN, $config{filetypes_conf}) || error("$config{filetypes_conf}: $!"); - while () { - chomp; - if (/^\$ext\((.*)\)=(.*)$/) { - $ext2lang{$_}=$1 foreach $1, split ' ', $2; + open (my $f, $config{filetypes_conf}) || error("$config{filetypes_conf}: $!"); + local $/=undef; + my $config=<$f>; + close $f; + + # highlight >= 3.2 format (bind-style) + while ($config=~m/Lang\s*=\s*\"([^"]+)\"[,\s]+Extensions\s*=\s*{([^}]+)}/sg) { + my $lang=$1; + foreach my $bit (split ',', $2) { + $bit=~s/.*"(.*)".*/$1/s; + $ext2lang{$bit}=$lang; } } - close IN; + + # highlight < 3.2 format + if (! keys %ext2lang) { + foreach (split("\n", $config)) { + if (/^\$ext\((.*)\)=(.*)$/) { + $ext2lang{$_}=$1 foreach $1, split ' ', $2; + } + } + } + $filetypes_read=1; }