X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FGitalist%2FView%2FSyntaxHighlight.pm;h=f0b8f6ed6986996e016c14ebdb4983fc66318080;hb=18add14a16a5b34bb95f3937690f0bd7522e5821;hp=9c2834151450b6748a8521f91b2852dd3fd41056;hpb=cea75f84acfeeb2bbdcc21550bac82001d3c072c;p=catagits%2FGitalist.git diff --git a/lib/Gitalist/View/SyntaxHighlight.pm b/lib/Gitalist/View/SyntaxHighlight.pm index 9c28341..f0b8f6e 100644 --- a/lib/Gitalist/View/SyntaxHighlight.pm +++ b/lib/Gitalist/View/SyntaxHighlight.pm @@ -5,7 +5,6 @@ use namespace::autoclean; extends 'Catalyst::View'; use Syntax::Highlight::Engine::Kate (); -use Syntax::Highlight::Engine::Kate::Perl (); use HTML::Entities qw(encode_entities); @@ -17,7 +16,10 @@ sub process { sub render { my ($self, $c, $blob, $args) = @_; - + + # Don't bother with anything over 64kb, it'll be tragically slow. + return encode_entities $blob if length $blob > 65536; + my $lang = $args->{language}; my $ret; @@ -50,6 +52,30 @@ sub render { ); my $hltxt = $hl->highlightText($blob); + + # Line numbering breaks #define foo\nbar + # So let's fix that by closing all spans at end-of-line and opening + # new ones on the next, if needed. + + my @lines = split(/\n/, $hltxt); + my $last_class = undef; + map { + unless($_ =~ s/^<\/span>//) { + if($last_class) { + $_ = "" . $_; + } + } + $last_class = undef; + if($_ =~ /(?!.*<\/span>)/) { + $last_class = $1; + } + if($_ !~ /<\/span>$/) { + $_ .= ""; + } + $_; + } @lines; + + $hltxt = join("\n", @lines); $hltxt =~ s/([^[:ascii:]])/encode_entities($1)/eg; $hltxt; };