Skip to content

armgit / memos

Public Imported from GitHub
0

Memos is an open-source, self-hosted note-taking app that brings your everyday thoughts together in a personal timeline. Your data stays yours, and you choose what to keep private or share.

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

s4kurae5ed6e7ec60e
diff --git a/web/src/utils/markdown-manipulation.ts b/web/src/utils/markdown-manipulation.ts
index a85a7d46c..f1461547c 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 000000000..beaaa2738
--- /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(`# <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",
+ },
+ ]);
+ });
+});