X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FGitalist.git;a=blobdiff_plain;f=lib%2FGitalist%2FView%2FSyntaxHighlight.pm;fp=lib%2FGitalist%2FView%2FSyntaxHighlight.pm;h=f0b8f6ed6986996e016c14ebdb4983fc66318080;hp=4d98c36e9fcab5269b98a6b3e2a3319f62bcd627;hb=0493e65778d860a3c78cd429b0ae843e545ebfec;hpb=d3f6d19341def5501b751fe4aba828f328a1d4aa
diff --git a/lib/Gitalist/View/SyntaxHighlight.pm b/lib/Gitalist/View/SyntaxHighlight.pm
index 4d98c36..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);
@@ -19,7 +18,7 @@ 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 > 8192;
+ return encode_entities $blob if length $blob > 65536;
my $lang = $args->{language};
@@ -53,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;
};