diff --git a/theme/src/client/composables/outline.ts b/theme/src/client/composables/outline.ts index b0366965..ffa75d8f 100644 --- a/theme/src/client/composables/outline.ts +++ b/theme/src/client/composables/outline.ts @@ -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 `` or more + // maybe `` 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 []