1#! /usr/bin/perl -w 2 3# Convert a jhightlight html/css file into html with style tags 4# Only works with: 5# pre.c2html {} 6# pre.c2html span.foo {} 7 8if (@ARGV < 2) { die " Format: $0 <HTML> <CSS>"; } 9 10open(HTML, "< $ARGV[0]") || die "open($ARGV[0]): $!"; 11open(CSS, "< $ARGV[1]") || die "open($ARGV[1]): $!"; 12 13my %css2style = (); 14 15while (<CSS>) 16{ 17 /^ \s+ pre[.]c2html # Everything starts as a sub of pre 18 (?:\s+ span[.]([a-z0-9]+))? # If it's not pre itself, find the span class. 19 \s+ { \s ([^}]+) \s } $/x || # Capture the style info. 20 next; 21 22 my $class = $1; 23 my $style = $2; 24 25 if (! defined ($class)) { $class = "c2html"; } 26 27 $css2style{$class} = $style; 28} 29 30 31while (<HTML>) 32{ 33 s/class="([^"]+)"/style="$css2style{$1}"/g; 34 print; 35} 36 37