Merge pull request #215 from fix-205
CI / test (push) Successful in 46s
CI / docker (push) Successful in 42s

Fix #205: stop gutter drift from phantom newline rows
This commit was merged in pull request #215.
This commit is contained in:
fen
2026-09-10 18:15:03 +00:00
3 changed files with 19 additions and 3 deletions
+10 -1
View File
@@ -17,7 +17,10 @@
// because HighlightCode highlights per line) in a .codeline block. The
// spans are display:block, so they are joined with '' — a '\n' join leaves
// newline text nodes between blocks that pre-wrap renders as an extra line
// box per line, which would shift every following number down one row (#167).
// box per line, which would shift every following number down one row (#167,
// #205). Whitespace-only text nodes are also stripped defensively below: any
// that reach the DOM (older cached HTML, other templates) render as phantom
// rows under white-space: pre and drift the gutter.
function splitLines() {
var html = body.innerHTML;
var parts = html.split('\n');
@@ -26,6 +29,12 @@
out.push('<span class="codeline">' + parts[i] + '</span>');
}
body.innerHTML = out.join('');
// #205: strip whitespace-only text nodes between the .codeline blocks.
var ws = [];
for (var n = body.firstChild; n; n = n.nextSibling) {
if (n.nodeType === 3 && !/\S/.test(n.nodeValue)) ws.push(n);
}
for (var w = 0; w < ws.length; w++) body.removeChild(ws[w]);
}
// One .gutline block per visual row. The gutter must reproduce the code