X-Git-Url: https://sipb.mit.edu/gitweb.cgi/ikiwiki.git/blobdiff_plain/ea48e1c038bfdab5820383cb885360c1d3fe2a14..aa65300c2f6a22d4372020b4b5b1a04b5842531a:/IkiWiki/Plugin/highlight.pm diff --git a/IkiWiki/Plugin/highlight.pm b/IkiWiki/Plugin/highlight.pm index 934e64bed..9d05e9fcf 100644 --- a/IkiWiki/Plugin/highlight.pm +++ b/IkiWiki/Plugin/highlight.pm @@ -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; }