1 package Gitalist::View::SyntaxHighlight;
3 use namespace::autoclean;
5 extends 'Catalyst::View';
7 use Syntax::Highlight::Engine::Kate ();
9 use HTML::Entities qw(encode_entities);
14 $c->res->body($self->render($c, $c->res->body, $c->stash));
18 my ($self, $c, $blob, $args) = @_;
20 # Don't bother with anything over 64kb, it'll be tragically slow.
21 return encode_entities $blob if length $blob > 65536;
23 my $lang = $args->{language};
27 # via http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
29 no warnings 'redefine';
30 local *Syntax::Highlight::Engine::Kate::Template::logwarning
31 = sub { die @_ }; # i really don't care
32 my $hl = Syntax::Highlight::Engine::Kate->new(
42 # convert Kate's internal representation into
43 # <span class="<internal name>"> value </span>
45 $_ => [ qq{<span class="$_">}, '</span>' ]
47 qw/Alert BaseN BString Char Comment DataType
48 DecVal Error Float Function IString Keyword
49 Normal Operator Others RegionMarker Reserved
50 String Variable Warning/,
54 my $hltxt = $hl->highlightText($blob);
55 $hltxt =~ s/([^[:ascii:]])/encode_entities($1)/eg;
61 return $ret || encode_entities($blob);
64 __PACKAGE__->meta->make_immutable;
70 Gitalist::View::SyntaxHighlight - Responsible for syntax highlighting code
74 Catalyst View for Syntax highlighting.
84 See L<Gitalist> for authors.
88 See L<Gitalist> for the license.