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 | |
c8870bd3 |
11 | use HTML::Entities qw(encode_entities); |
12 | |
7e54e579 |
13 | sub process { |
14 | my($self, $c) = @_; |
c8870bd3 |
15 | |
16 | if($c->stash->{filename} =~ /\.p[lm]$/) { |
17 | # via |
18 | # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136 |
19 | eval { |
20 | no warnings 'redefine'; |
21 | local *Syntax::Highlight::Engine::Kate::Template::logwarning |
22 | = sub { die @_ }; # i really don't care |
23 | my $hl = Syntax::Highlight::Engine::Kate->new( |
24 | language => 'Perl', |
25 | substitutions => { |
26 | "<" => "<", |
27 | ">" => ">", |
28 | "&" => "&", |
29 | q{'} => "'", |
30 | q{"} => """, |
31 | }, |
32 | format_table => { |
33 | # convert Kate's internal representation into |
34 | # <span class="<internal name>"> value </span> |
35 | map { |
36 | $_ => [ qq{<span class="$_">}, '</span>' ] |
37 | } |
38 | qw/Alert BaseN BString Char Comment DataType |
39 | DecVal Error Float Function IString Keyword |
40 | Normal Operator Others RegionMarker Reserved |
41 | String Variable Warning/, |
42 | }, |
43 | ); |
44 | |
45 | $c->stash->{blob} = $hl->highlightText($c->stash->{blob}); |
46 | }; |
47 | warn $@ if $@; |
48 | } else { |
49 | $c->stash->{blob} = encode_entities($c->stash->{blob}); |
50 | } |
7e54e579 |
51 | |
52 | $c->forward('View::Default'); |
53 | } |
54 | |
1ef8dc7d |
55 | __PACKAGE__->meta->make_immutable; |