fix: align memo outline links with rendered headings (#6159)

This commit is contained in:
s4kura 2026-08-07 09:51:48 +08:00 committed by GitHub
parent 3f567fda45
commit e5ed6e7ec6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 18 additions and 0 deletions

View file

@ -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 "";

View file

@ -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(`# <ruby>連濁<rt>れんだく</rt></ruby>: "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",
},
]);
});
});