Skip to content

Commit 632d188

Browse files
authored
Merge pull request #1425 from dtolnay/hljs
Fix missing </span> on last boring line
2 parents dc96ade + 0415dda commit 632d188

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

book/build.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,14 @@ while (dirs.length) {
6565
return;
6666
}
6767
const lang = langClass.replace('language-', '');
68-
const lines = node.html().split('\n');
69-
const boring = lines.map((line) =>
68+
const originalLines = node.html().split('\n');
69+
const boring = originalLines.map((line) =>
7070
line.includes('<span class="boring">'),
7171
);
72-
const ellipsis = lines.map((line) => line.includes('// ...'));
72+
const ellipsis = originalLines.map((line) => line.includes('// ...'));
7373
const target = entities.decode(node.text());
74-
const highlighted = hljs.highlight(lang, target).value;
75-
const result = highlighted
76-
.split('\n')
74+
const highlightedLines = hljs.highlight(lang, target).value.split('\n');
75+
const result = highlightedLines
7776
.map(function (line, i) {
7877
if (boring[i]) {
7978
line = '<span class="boring">' + line;
@@ -83,6 +82,9 @@ while (dirs.length) {
8382
if (i > 0 && (boring[i - 1] || ellipsis[i - 1])) {
8483
line = '</span>' + line;
8584
}
85+
if (i + 1 === highlightedLines.length && (boring[i] || ellipsis[i])) {
86+
line = line + '</span>';
87+
}
8688
return line;
8789
})
8890
.join('\n');

0 commit comments

Comments
 (0)