rubychan / coderay

Fast and easy syntax highlighting for selected languages, written in Ruby.
http://coderay.rubychan.de/
Other
846 stars 115 forks source link

Misaligned line numbers in diff files with `line_numbers: :inline` #232

Open pablobm opened 5 years ago

pablobm commented 5 years ago

Say we have a diff file, test.diff:

--- file1   2018-12-26 11:14:56.000000000 +0000
+++ file2   2018-12-26 11:15:08.000000000 +0000
@@ -1,4 +1,3 @@
 a
-bcd
-ef
+bCd
 g

And we run CodeRay with the following options:

CodeRay.scan(File.read("test.diff"), :diff).page(css: :class, line_numbers: :inline)

The resulting HTML+CSS shows the line numbers misaligned, as follows:

bug-original

The following example is the same output, with the CSS rules width: 40em; margin: auto; applied to the .CodeRay block to highlight "wrapped-over" line numbers and content:

bug-limited-width

This is the expected behaviour, achieved by not using the option line_numbers: :inline:

expected-behaviour

pablobm commented 5 years ago

At first inspection, it would appear that the CSS properties for .CodeRay .line don't play well with the line numbers. This class is applied to the lines with colour background to allow the colour cover the whole line. When these properties are removed, the problem disappears, but the colour stops covering the whole line:

css-workaround