Skip to content

Commit 81073e7

Browse files
committed
refactor: improve code readability in C++ syntax highlighting logic
1 parent 3016e69 commit 81073e7

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

antora-ui/src/js/vendor/cpp-highlight.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,15 @@ const CppHighlight = (function () {
7676
i += 2
7777
let depth = 1
7878
while (i < n && depth > 0) {
79-
if (code.slice(i, i + 2) === '[[') { depth++; i += 2 } else if (code.slice(i, i + 2) === ']]') { depth--; i += 2 } else i++
79+
if (code.slice(i, i + 2) === '[[') {
80+
depth++
81+
i += 2
82+
} else if (code.slice(i, i + 2) === ']]') {
83+
depth--
84+
i += 2
85+
} else {
86+
i++
87+
}
8088
}
8189
result.push(span('attribute', code.slice(start, i)))
8290
continue

antora-ui/src/js/vendor/highlight.bundle.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
'.doc pre.highlight code[data-lang="c++"].hljs',
2121
]
2222

23-
var processedCount = 0
24-
2523
cppSelectors.forEach(function (selector) {
2624
try {
2725
document.querySelectorAll(selector).forEach(function (el) {
@@ -34,16 +32,11 @@
3432

3533
// Mark as processed with our custom highlighter
3634
el.classList.add('cpp-highlight')
37-
processedCount++
3835
})
3936
} catch (e) {
4037
console.warn('cpp-highlight error:', selector, e)
4138
}
4239
})
43-
44-
if (processedCount > 0) {
45-
console.log('cpp-highlight: Replaced ' + processedCount + ' C++ code blocks')
46-
}
4740
}
4841

4942
// Process C++ blocks after highlight.js runs

0 commit comments

Comments
 (0)