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=de745abebb6645505900c63169149bee474e41b1;hb=18add14a16a5b34bb95f3937690f0bd7522e5821;hpb=a8f570133294adb58620440e75c2cca0d32e0934
diff --git a/lib/Gitalist/View/SyntaxHighlight.pm b/lib/Gitalist/View/SyntaxHighlight.pm
index de745ab..f0b8f6e 100644
--- a/lib/Gitalist/View/SyntaxHighlight.pm
+++ b/lib/Gitalist/View/SyntaxHighlight.pm
@@ -52,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;
};