From e5ed6e7ec60e141d6e354f3ab59906c2c47dccac Mon Sep 17 00:00:00 2001 From: s4kura <1761015783@qq.com> Date: Fri, 7 Aug 2026 09:51:48 +0800 Subject: [PATCH] fix: align memo outline links with rendered headings (#6159) --- web/src/utils/markdown-manipulation.ts | 2 ++ web/tests/markdown-manipulation.test.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 web/tests/markdown-manipulation.test.ts diff --git a/web/src/utils/markdown-manipulation.ts b/web/src/utils/markdown-manipulation.ts index a85a7d46..f1461547 100644 --- a/web/src/utils/markdown-manipulation.ts +++ b/web/src/utils/markdown-manipulation.ts @@ -137,11 +137,13 @@ export function extractHeadings(markdown: string): HeadingItem[] { } interface MdastNode { + type?: string; value?: string; children?: MdastNode[]; } function getNodeText(node: MdastNode): string { + if (node.type === "html") return ""; if (node.value) return node.value; if (node.children) return node.children.map(getNodeText).join(""); return ""; diff --git a/web/tests/markdown-manipulation.test.ts b/web/tests/markdown-manipulation.test.ts new file mode 100644 index 00000000..beaaa273 --- /dev/null +++ b/web/tests/markdown-manipulation.test.ts @@ -0,0 +1,16 @@ +import { describe, expect, it } from "vitest"; +import { extractHeadings } from "@/utils/markdown-manipulation"; + +describe("extractHeadings", () => { + it("uses rendered text for headings containing inline HTML", () => { + const headings = extractHeadings(`# 連濁れんだく: "Why Hito-Bito isn't Hito-Hito"`); + + expect(headings).toEqual([ + { + text: `連濁れんだく: "Why Hito-Bito isn't Hito-Hito"`, + level: 1, + slug: "why-hito-bito-isnt-hito-hito", + }, + ]); + }); +});