Skip to content

Commit

Permalink
syntaxhighlighter: don't pad empty lines with spaces
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
haarg committed Nov 13, 2024
1 parent 640af34 commit c6539d6
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
8 changes: 8 additions & 0 deletions root/static/js/syntaxhighlighter.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,14 @@ Renderer.prototype.getHtml = function(...args) {
return html;
};

const wrapLine = Renderer.prototype.wrapLine;
Renderer.prototype.wrapLine = function(lineIndex, lineNumber, lineHtml) {
if (lineHtml == ' ') {
lineHtml = '';
}
return wrapLine.call(this, lineIndex, lineNumber, lineHtml);
};

// on pod pages, set the language to perl if no other language is set
CODE: for (const code of document.querySelectorAll(".pod pre > code")) {
for (const className of code.classList) {
Expand Down
1 change: 1 addition & 0 deletions root/static/less/syntaxhighlighter-theme.less
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

.line {
white-space: pre;
min-height: 1.2em;
}

// main table and columns
Expand Down

0 comments on commit c6539d6

Please sign in to comment.