Skip to content

Commit c6539d6

Browse files
committed
syntaxhighlighter: don't pad empty lines with spaces
Rather than padding empty lines with single spaces, we can use CSS to ensure correct alignment. This avoids copy/pasting code including invented spaces on empty lines.
1 parent 640af34 commit c6539d6

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

root/static/js/syntaxhighlighter.mjs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ Renderer.prototype.getHtml = function(...args) {
147147
return html;
148148
};
149149

150+
const wrapLine = Renderer.prototype.wrapLine;
151+
Renderer.prototype.wrapLine = function(lineIndex, lineNumber, lineHtml) {
152+
if (lineHtml == ' ') {
153+
lineHtml = '';
154+
}
155+
return wrapLine.call(this, lineIndex, lineNumber, lineHtml);
156+
};
157+
150158
// on pod pages, set the language to perl if no other language is set
151159
CODE: for (const code of document.querySelectorAll(".pod pre > code")) {
152160
for (const className of code.classList) {

root/static/less/syntaxhighlighter-theme.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
.line {
2424
white-space: pre;
25+
min-height: 1.2em;
2526
}
2627

2728
// main table and columns

0 commit comments

Comments
 (0)