Skip to content

Commit 1cf33c8

Browse files
committed
Fix output when hljs multi-line element contains an empty line
When a highlightjs multi-line element (for instance a multi-line comment) contains an empty line, the resulting output numbered line was containing a "{1}" string. This fix handles the empty line special case.
1 parent e03ee42 commit 1cf33c8

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

dist/highlightjs-line-numbers.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/highlightjs-line-numbers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@
150150
var lines = getLines(element.innerHTML);
151151

152152
for (var i = 0, result = ''; i < lines.length; i++) {
153-
result += format('<span class="{0}">{1}</span>\n', [ className, lines[i] ]);
153+
var lineText = lines[i].length > 0 ? lines[i] : ' ';
154+
result += format('<span class="{0}">{1}</span>\n', [ className, lineText ]);
154155
}
155156

156157
element.innerHTML = result.trim();

0 commit comments

Comments
 (0)