fix: align memo outline links with rendered headings (#6159)
This commit is contained in:
parent
3f567fda45
commit
e5ed6e7ec6
2 changed files with 18 additions and 0 deletions
|
|
@ -137,11 +137,13 @@ export function extractHeadings(markdown: string): HeadingItem[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MdastNode {
|
interface MdastNode {
|
||||||
|
type?: string;
|
||||||
value?: string;
|
value?: string;
|
||||||
children?: MdastNode[];
|
children?: MdastNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getNodeText(node: MdastNode): string {
|
function getNodeText(node: MdastNode): string {
|
||||||
|
if (node.type === "html") return "";
|
||||||
if (node.value) return node.value;
|
if (node.value) return node.value;
|
||||||
if (node.children) return node.children.map(getNodeText).join("");
|
if (node.children) return node.children.map(getNodeText).join("");
|
||||||
return "";
|
return "";
|
||||||
|
|
|
||||||
16
web/tests/markdown-manipulation.test.ts
Normal file
16
web/tests/markdown-manipulation.test.ts
Normal 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",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Reference in a new issue