Skip to content

Commit 7bad736

Browse files
committed
feat: support inlineCode & link in toc
1 parent e91ef7e commit 7bad736

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

packages/island/src/node/plugin-mdx/remarkPlugins/toc.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ interface TocItem {
1212
depth: number;
1313
}
1414

15+
interface ChildNode {
16+
type: 'link' | 'text' | 'inlineCode';
17+
value: string;
18+
children?: ChildNode[];
19+
}
20+
1521
export const remarkPluginToc: Plugin = () => {
1622
// eslint-disable-next-line @typescript-eslint/no-explicit-any
1723
return (tree: any) => {
@@ -27,7 +33,13 @@ export const remarkPluginToc: Plugin = () => {
2733

2834
if (node.type === 'heading' && node.depth > 1 && node.depth < 5) {
2935
const originText = node.children
30-
.map((child: { value: string }) => child.value)
36+
.map((child: ChildNode) => {
37+
if (child.type === 'link') {
38+
return child.children?.map((item) => item.value).join('');
39+
} else {
40+
return child.value;
41+
}
42+
})
3143
.join('');
3244
const id = slugger.slug(originText);
3345
const depth = node.depth;

packages/plugin-search/types.d.ts

+5
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ declare module '*.svg' {
55
React.SVGProps<SVGSVGElement> & AttributifyAttributes
66
>;
77
export = ReactComponent;
8+
}
9+
10+
declare module '*.module.scss' {
11+
const classes: { [key: string]: string };
12+
export default classes;
813
}

0 commit comments

Comments
 (0)