Skip to content

Commit e5ed6e7

Browse files
authored
fix: align memo outline links with rendered headings (#6159)
1 parent 3f567fd commit e5ed6e7

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

web/src/utils/markdown-manipulation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,13 @@ export function extractHeadings(markdown: string): HeadingItem[] {
137137
}
138138

139139
interface MdastNode {
140+
type?: string;
140141
value?: string;
141142
children?: MdastNode[];
142143
}
143144

144145
function getNodeText(node: MdastNode): string {
146+
if (node.type === "html") return "";
145147
if (node.value) return node.value;
146148
if (node.children) return node.children.map(getNodeText).join("");
147149
return "";
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { describe, expect, it } from "vitest";
2+
import { extractHeadings } from "@/utils/markdown-manipulation";
3+
4+
describe("extractHeadings", () => {
5+
it("uses rendered text for headings containing inline HTML", () => {
6+
const headings = extractHeadings(`# <ruby>連濁<rt>れんだく</rt></ruby>: "Why Hito-Bito isn't Hito-Hito"`);
7+
8+
expect(headings).toEqual([
9+
{
10+
text: `連濁れんだく: "Why Hito-Bito isn't Hito-Hito"`,
11+
level: 1,
12+
slug: "why-hito-bito-isnt-hito-hito",
13+
},
14+
]);
15+
});
16+
});

0 commit comments

Comments
 (0)