#!/usr/bin/perl use strict; use warnings; my %css; my $fg = 'black'; # default foreground colour. # You might want to change this at least for a dark background. # part 1: Read the file (files even, in case you provide) while (<>) { my ($force, $from, $to, $name, $col, $att) = /^hi(?:ghlight)? (?: (!)?\s+link\s+(\w+)\s+(\w+) | \s+(\w+)\s+ (?= .*?guifg=( [a-zA-Z]+ | \#[0-9a-fA-F]{6} ) )? (?= .*?gui=( \w+ ) )? ) /x; next unless $from or $name and ($col or $att); #{ # no warnings 'uninitialized'; # print "$force, $from, $to, $name, $col, $att\n"; #} if ($name) { $name = lc $name; $css{$name} = {}; $css{$name}->{col} = $col if $col; $css{$name}->{col} ||= $fg; $css{$name}->{att} = $att if $att and uc $att ne 'NONE'; } else { # link next if $css{$from} and not $force; $from = lc $from; $css{$from}->{lnk} = lc $to; } } #part 2: Resolve "links". # Does Vim handle forward declared links? # Anyway, the code does. my $more = keys %css; while (--$more) { my $found = 0; for my $group (keys %css) { next unless $css{$group}->{lnk}; $found = 1; my $to = $css{$group}->{lnk}; if (exists $css{$to}) { $css{$group} = $css{$to}; } else { $css{$group} = {col => $fg}; } } next unless $found; } #part 3: Create the CSS # Use this Vim "group" => JS className translation. # Is Vim case sensitive on the names? my %map = ( quotedString => 'string', comment => 'comment', operator => 'normal', builtinVariable => 'identifier', variableSpecifier => 'identifier', keyword => 'keyword', builtinFunction => 'keyword', identifier => 'identifier', number => 'number', ); for my $class (keys %map) { my $id = $map{$class}; my $cid = $css{$id} || $css{Normal}; my $col = lc $cid->{col} || $fg; my $att = $cid->{att}||q() eq 'bold' ? "\n font-weight:bold;" : q(); print <