Skip to content

Commit cfe8016

Browse files
authored
fix: formatted TOC title (#104)
1 parent 2941ce3 commit cfe8016

File tree

4 files changed

+8
-1
lines changed

4 files changed

+8
-1
lines changed

dev/src/routes/index.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ title: Test2
66

77
## Heading 2
88

9+
## Heading 2 with `code`
10+
911
### Heading 3
1012

1113
#### Heading 4

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@
151151
"hastscript": "^9.0.0",
152152
"mdast-util-find-and-replace": "^3.0.1",
153153
"mdast-util-mdx-jsx": "^3.2.0",
154+
"mdast-util-to-string": "^4.0.0",
154155
"mdast-util-toc": "^7.1.0",
155156
"rehype-autolink-headings": "^7.1.0",
156157
"rehype-expressive-code": "^0.40.2",

pnpm-lock.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config/remark-plugins/toc.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { fromJs } from "esast-util-from-js";
22
import type { PhrasingContent } from "mdast";
33
import { findAndReplace } from "mdast-util-find-and-replace";
44
import { type Options, toc } from "mdast-util-toc";
5+
import { toString } from "mdast-util-to-string"
56

67
interface ParagraphNode {
78
type: "paragraph";
@@ -31,7 +32,7 @@ interface TOCTree {
3132

3233
function mapNode(node: ListItemNode): TOCTree {
3334
return {
34-
title: node.children[0].children[0].children[0].value,
35+
title: toString(node.children[0].children[0].children),
3536
href: node.children[0].children[0].url,
3637
children: (node.children[1]?.children ?? []).map(mapNode),
3738
};

0 commit comments

Comments
 (0)