Commit | Line | Data |
7d44d2b1 |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
e307fe4f |
6 | use Syntax::Highlight::Perl::Improved ':FULL'; |
7d44d2b1 |
7 | |
8 | my $color_table = { |
9 | 'Variable_Scalar' => 'color:#080;', |
10 | 'Variable_Array' => 'color:#f70;', |
11 | 'Variable_Hash' => 'color:#80f;', |
12 | 'Variable_Typeglob' => 'color:#f03;', |
13 | 'Subroutine' => 'color:#980;', |
14 | 'Quote' => 'color:#00a;', |
15 | 'String' => 'color:#00a;', |
16 | 'Comment_Normal' => 'color:#069;font-style:italic;', |
17 | 'Comment_POD' => 'color:#014;font-size:11pt;', |
18 | 'Bareword' => 'color:#3A3;', |
19 | 'Package' => 'color:#900;', |
20 | 'Number' => 'color:#f0f;', |
21 | 'Operator' => 'color:#000;', |
22 | 'Symbol' => 'color:#000;', |
23 | 'Keyword' => 'color:#000;', |
24 | 'Builtin_Operator' => 'color:#300;', |
25 | 'Builtin_Function' => 'color:#001;', |
26 | 'Character' => 'color:#800;', |
27 | 'Directive' => 'color:#399;font-style:italic;', |
28 | 'Label' => 'color:#939;font-style:italic;', |
29 | 'Line' => 'color:#000;', |
30 | }; |
31 | |
e307fe4f |
32 | my $formatter = Syntax::Highlight::Perl::Improved->new(); |
7d44d2b1 |
33 | |
34 | $formatter->define_substitution( |
35 | '<' => '<', |
36 | '>' => '>', |
37 | '&' => '&' |
38 | ); |
39 | |
40 | while ( my ( $type, $style ) = each %{$color_table} ) { |
41 | $formatter->set_format( |
42 | $type, |
43 | [ |
44 | qq|<span style="$style">|, |
45 | '</span>' |
46 | ] |
47 | ); |
48 | } |
49 | |
50 | my $file = shift || die "Give me a perl file to colorize!\n"; |
51 | -e $file or die "There's no such file: $file\n"; |
52 | |
53 | open F, '<', $file or die $!; |
54 | |
55 | print '<pre style="font-size:10pt;color:#336;">'; |
56 | while (<F>) { |
57 | print $formatter->format_string; |
58 | } |
59 | print "</pre>"; |
60 | close F; |
61 | |
62 | exit 0; |
63 | |
64 | 1; |