added subclassing tutorials
[gitmo/moose-website.git] / bin / colorize_code.pl
CommitLineData
7d44d2b1 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
e307fe4f 6use Syntax::Highlight::Perl::Improved ':FULL';
7d44d2b1 7
8my $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 32my $formatter = Syntax::Highlight::Perl::Improved->new();
7d44d2b1 33
34$formatter->define_substitution(
35 '<' => '&lt;',
36 '>' => '&gt;',
37 '&' => '&amp;'
38);
39
40while ( my ( $type, $style ) = each %{$color_table} ) {
41 $formatter->set_format(
42 $type,
43 [
44 qq|<span style="$style">|,
45 '</span>'
46 ]
47 );
48}
49
50my $file = shift || die "Give me a perl file to colorize!\n";
51-e $file or die "There's no such file: $file\n";
52
53open F, '<', $file or die $!;
54
55print '<pre style="font-size:10pt;color:#336;">';
56while (<F>) {
57 print $formatter->format_string;
58}
59print "</pre>";
60close F;
61
62exit 0;
63
641;