1 package Gitalist::View::SyntaxHighlight;
3 use Gitalist; # ->path_to
4 use namespace::autoclean;
6 extends 'Catalyst::View';
8 use Syntax::Highlight::Engine::Kate ();
9 use Syntax::Highlight::Engine::Kate::Perl ();
11 use HTML::Entities qw(encode_entities);
16 # If we're not going to highlight the blob unsure that it's ready to go
18 if($c->stash->{filename} =~ /\.p[lm]$/) {
20 # http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
22 no warnings 'redefine';
23 local *Syntax::Highlight::Engine::Kate::Template::logwarning
24 = sub { die @_ }; # i really don't care
25 my $hl = Syntax::Highlight::Engine::Kate->new(
35 # convert Kate's internal representation into
36 # <span class="<internal name>"> value </span>
38 $_ => [ qq{<span class="$_">}, '</span>' ]
40 qw/Alert BaseN BString Char Comment DataType
41 DecVal Error Float Function IString Keyword
42 Normal Operator Others RegionMarker Reserved
43 String Variable Warning/,
47 $c->stash->{blob} = $hl->highlightText($c->stash->{blob});
51 $c->stash->{blob} = encode_entities($c->stash->{blob});
54 $c->forward('View::Default');
57 __PACKAGE__->meta->make_immutable;