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