Gave the /commit page a diff-tree.
[catagits/Gitalist.git] / lib / Gitalist / View / SyntaxHighlight.pm
CommitLineData
7e54e579 1package Gitalist::View::SyntaxHighlight;
2use Moose;
3use Gitalist; # ->path_to
4use namespace::autoclean;
5
6extends 'Catalyst::View';
7
8use Syntax::Highlight::Engine::Kate ();
9use Syntax::Highlight::Engine::Kate::Perl ();
10
11sub process {
12 my($self, $c) = @_;
13 # via
14 # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
15 eval {
16 no warnings 'redefine';
17 local *Syntax::Highlight::Engine::Kate::Template::logwarning
18 = sub { die @_ }; # i really don't care
19 my $hl = Syntax::Highlight::Engine::Kate->new(
20 language => 'Perl',
21 substitutions => {
22 "<" => "&lt;",
23 ">" => "&gt;",
24 "&" => "&amp;",
25 q{'} => "&apos;",
26 q{"} => "&quot;",
27 },
28 format_table => {
29 # convert Kate's internal representation into
30 # <span class="<internal name>"> value </span>
31 map {
32 $_ => [ qq{<span class="$_">}, '</span>' ]
33 }
34 qw/Alert BaseN BString Char Comment DataType
35 DecVal Error Float Function IString Keyword
36 Normal Operator Others RegionMarker Reserved
37 String Variable Warning/,
38 },
39 );
40
41 $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
42 };
43
44 warn $@ if $@;
45
46 $c->forward('View::Default');
47}
48
1ef8dc7d 49__PACKAGE__->meta->make_immutable;