fix: abbr incorrectly rendered in toc, close #488 (#494)

This commit is contained in:
pengzhanbo 2025-03-01 23:44:01 +08:00 committed by GitHub
parent 8608a716e6
commit 2505e7f623
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -99,14 +99,15 @@ function serializeHeader(h: Element): string {
) {
continue
}
ret += node.textContent
const clone = node.cloneNode(true)
clearHeaderNodeList(Array.from(clone.childNodes))
ret += clone.textContent
}
else if (node.nodeType === 3) {
ret += node.textContent
}
}
// maybe `<hx><a href="#"></a><a href="xxx"></a</hx>` or more
// maybe `<hx><a href="#"></a><a href="xxx"></a></hx>` or more
let next = anchor?.nextSibling
while (next) {
if (next.nodeType === 1 || next.nodeType === 3)
@ -117,6 +118,21 @@ function serializeHeader(h: Element): string {
return ret.trim()
}
function clearHeaderNodeList(list?: ChildNode[]) {
if (list?.length) {
for (const node of list) {
if (node.nodeType === 1) {
if ((node as Element).classList.contains('ignore-header')) {
node.remove()
}
else {
clearHeaderNodeList(Array.from(node.childNodes))
}
}
}
}
}
export function resolveHeaders(headers: MenuItem[], range?: ThemeOutline): MenuItem[] {
if (range === false)
return []