Skip to content

Commit a64b07a

Browse files
committed
refactor(js): improve robustness of line numbering and TOC anchoring
1 parent 587f817 commit a64b07a

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

assets/js/code-block.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ document.addEventListener('DOMContentLoaded', () => {
2323
});
2424
});
2525

26-
const codeLines = code.innerHTML.split(/\r?\n/);
26+
const codeLines = code.textContent.split(/\r?\n/);
2727
const hasTrailingEmptyLine = codeLines.length > 0 && codeLines[codeLines.length - 1].trim() === '';
2828
if (hasTrailingEmptyLine) {
2929
codeLines.pop();

assets/js/toc.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ document.addEventListener('DOMContentLoaded', () => {
4545
if (currentId) {
4646
tocLinks.forEach(link => {
4747
link.classList.remove('active');
48-
// Decode URI component to handle non-ASCII IDs if any
49-
const href = link.getAttribute('href');
50-
if (href === `#${currentId}`) {
48+
if (link.hash === `#${currentId}`) {
5149
link.classList.add('active');
5250
}
5351
});

0 commit comments

Comments
 (0)