]> sipb.mit.edu Git - ikiwiki.git/blobdiff - IkiWiki/Plugin/highlight.pm
releasing version 3.20101201
[ikiwiki.git] / IkiWiki / Plugin / highlight.pm
index 5674f0b4aa150557fbb75e76e208a284dd145288..9d05e9fcf49126c7d1f97d815e6c3435a82cd83a 100644 (file)
@@ -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 => "htmlizeformat", id => "highlight", call =>
-               \&htmlizeformat);
+       hook(type => "htmlizeformat", id => "highlight", 
+               call => \&htmlizeformat, last => 1);
 }
 
 sub getsetup () {
@@ -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 (<IN>) {
-               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;
 }