Commit | Line | Data |
7e54e579 |
1 | package Gitalist::View::SyntaxHighlight; |
2 | use Moose; |
3 | use Gitalist; # ->path_to |
4 | use namespace::autoclean; |
5 | |
6 | extends 'Catalyst::View'; |
7 | |
8 | use Syntax::Highlight::Engine::Kate (); |
9 | use Syntax::Highlight::Engine::Kate::Perl (); |
10 | |
11 | sub 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 | "<" => "<", |
23 | ">" => ">", |
24 | "&" => "&", |
25 | q{'} => "'", |
26 | q{"} => """, |
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 | |
49 | 1; |