highlight: Support new format of filetypes.conf used by version 3.2 of the highlight...
authorJoey Hess <joey@kitenet.net>
Sat, 20 Nov 2010 16:55:26 +0000 (12:55 -0400)
committerJoey Hess <joey@kitenet.net>
Sat, 20 Nov 2010 16:55:26 +0000 (12:55 -0400)
IkiWiki/Plugin/highlight.pm
debian/changelog

index 934e64bed708f032283c11660add6ac02d8ffe4a..9d05e9fcf49126c7d1f97d815e6c3435a82cd83a 100644 (file)
@@ -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;
 }
 
index 65c2353171dada06ea295218088c26ae2a2011e1..ecd028a0c92214ee1f4d92766e33b5ca81f62427 100644 (file)
@@ -9,6 +9,8 @@ ikiwiki (3.20101113) UNRELEASED; urgency=low
     (Which doesn't include html5 just yet, but then the old version
     didn't either.) Bonus: 4 times faster than old regexp method.
   * Optimise glob() pagespec. (Thanks, Kathryn and smcv)
+  * highlight: Support new format of filetypes.conf used by version 3.2
+    of the highlight package.
 
  -- Joey Hess <joeyh@debian.org>  Tue, 16 Nov 2010 14:23:47 -0400