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 my $lang = $args->{language};
25 # via http://github.com/jrockway/angerwhale/blob/master/lib/Angerwhale/Format/Pod.pm#L136
27 no warnings 'redefine';
28 local *Syntax::Highlight::Engine::Kate::Template::logwarning
29 = sub { die @_ }; # i really don't care
30 my $hl = Syntax::Highlight::Engine::Kate->new(
40 # convert Kate's internal representation into
41 # <span class="<internal name>"> value </span>
43 $_ => [ qq{<span class="$_">}, '</span>' ]
45 qw/Alert BaseN BString Char Comment DataType
46 DecVal Error Float Function IString Keyword
47 Normal Operator Others RegionMarker Reserved
48 String Variable Warning/,
52 my $hltxt = $hl->highlightText($blob);
53 $hltxt =~ s/([^[:ascii:]])/encode_entities($1)/eg;
59 return $ret || encode_entities($blob);
62 __PACKAGE__->meta->make_immutable;
68 Gitalist::View::SyntaxHighlight - Responsible for syntax highlighting code
72 Catalyst View for Syntax highlighting.
82 See L<Gitalist> for authors.
86 See L<Gitalist> for the license.