#!/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 <<EOS; .$class { color: $col;$att } EOS }

In reply to Use your Vim colorscheme in perlmonks syntax highlighting by pKai

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.