From 2505e7f62391c18514cb4596b75fc25439dc1116 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Sat, 1 Mar 2025 23:44:01 +0800 Subject: [PATCH] fix: `abbr` incorrectly rendered in `toc`, close #488 (#494) --- theme/src/client/composables/outline.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) 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 []