Skip to content

Commit 4a5b6e3

Browse files
authored
refactor(core): replace @rspress/mdx-rs and html-to-text with @mdx-js/mdx createProcessor for toc and searchIndex generation (#3001)
1 parent 5310781 commit 4a5b6e3

File tree

19 files changed

+1069
-306
lines changed

19 files changed

+1069
-306
lines changed

e2e/fixtures/inline-markdown/index.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ test.describe('Inline markdown test', async () => {
156156
'delete',
157157
'This is a long string to test regex performance',
158158
'this is link rsbuild',
159-
'this is bold link', // FIXME: should be 'this is bold link rsbuild'
160-
'this is code link',
161-
'this is bold code link',
159+
'this is bold link rsbuild',
160+
'this is code link rsbuild',
161+
'this is bold code link rsbuild',
162162
]);
163163

164164
const overviewLinkCount = await overviewLinks.count();
@@ -178,9 +178,9 @@ test.describe('Inline markdown test', async () => {
178178
'<del>delete</del>',
179179
'<code>This is a long string to test regex performance</code>',
180180
'this is link rsbuild',
181-
'this is bold link',
182-
'this is code link',
183-
'this is bold code link',
181+
'this is bold link <strong>rsbuild</strong>',
182+
'this is code link <code>rsbuild</code>',
183+
'this is bold code link <strong><code>rsbuild</code></strong>',
184184
];
185185
for (const [index, html] of overviewLinkInnerHtml.entries()) {
186186
expect(html).toContain(expectedOverviewLinkInnerHtml[index]);

packages/core/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@
7070
"@mdx-js/react": "^3.1.1",
7171
"@rsbuild/core": "~1.7.2",
7272
"@rsbuild/plugin-react": "~1.4.2",
73-
"@rspress/mdx-rs": "0.6.6",
7473
"@rspress/shared": "workspace:*",
7574
"@shikijs/rehype": "^3.21.0",
7675
"@types/unist": "^3.0.3",
@@ -84,7 +83,6 @@
8483
"github-slugger": "^2.0.0",
8584
"hast-util-heading-rank": "^3.0.0",
8685
"hast-util-to-jsx-runtime": "^2.3.6",
87-
"html-to-text": "^9.0.5",
8886
"lodash-es": "^4.17.22",
8987
"mdast-util-mdx": "^3.0.0",
9088
"mdast-util-mdxjs-esm": "^2.0.1",
@@ -100,12 +98,14 @@
10098
"rehype-raw": "^7.0.0",
10199
"remark-gfm": "^4.0.1",
102100
"remark-mdx": "^3.1.1",
101+
"remark-parse": "^11.0.0",
103102
"remark-stringify": "^11.0.0",
104103
"scroll-into-view-if-needed": "^3.1.0",
105104
"shiki": "^3.21.0",
106105
"tinyglobby": "^0.2.15",
107106
"tinypool": "^1.1.1",
108107
"unified": "^11.0.5",
108+
"unist-util-remove": "^4.0.0",
109109
"unist-util-visit": "^5.0.0",
110110
"unist-util-visit-children": "^3.0.0"
111111
},
@@ -117,7 +117,6 @@
117117
"@rspress/config": "workspace:*",
118118
"@types/body-scroll-lock": "^3.1.2",
119119
"@types/hast": "^3.0.4",
120-
"@types/html-to-text": "^9.0.4",
121120
"@types/lodash-es": "^4.17.12",
122121
"@types/mdast": "^4.0.4",
123122
"@types/node": "^22.8.1",

packages/core/src/node/mdx/rehypePlugins/__snapshots__/headerAnchor.test.ts.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,6 @@ function _missingMdxReference(id, component) {
246246
247247
248248
MDXContent.__RSPRESS_PAGE_META = {};
249-
MDXContent.__RSPRESS_PAGE_META["inline-code.mdx"] = {"toc":[],"title":"Hello World ","headingTitle":"Hello World ","frontmatter":{}};
249+
MDXContent.__RSPRESS_PAGE_META["inline-code.mdx"] = {"toc":[],"title":"Hello World","headingTitle":"Hello World","frontmatter":{}};
250250
"
251251
`;
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
// Rstest Snapshot v1
2+
3+
exports[`toc > basic link in heading 1`] = `
4+
"import {Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs} from "react/jsx-runtime";
5+
import {useMDXComponents as _provideComponents} from "@mdx-js/react";
6+
import {Callout as $$$callout$$$} from "@theme";
7+
import {Link} from '@theme';
8+
function _createMdxContent(props) {
9+
const _components = {
10+
a: "a",
11+
code: "code",
12+
h1: "h1",
13+
h2: "h2",
14+
strong: "strong",
15+
..._provideComponents(),
16+
...props.components
17+
};
18+
return _jsxs(_Fragment, {
19+
children: [_jsxs(_components.h1, {
20+
id: "link",
21+
children: [_jsx(_components.a, {
22+
className: "rp-header-anchor",
23+
"aria-hidden": "true",
24+
href: "#link",
25+
children: "#"
26+
}), "link"]
27+
}), "\\n", _jsxs(_components.h2, {
28+
id: "this-is-link-rsbuild",
29+
children: [_jsx(_components.a, {
30+
className: "rp-header-anchor",
31+
"aria-hidden": "true",
32+
href: "#this-is-link-rsbuild",
33+
children: "#"
34+
}), "this is link ", _jsx(_components.a, {
35+
href: "https://rsbuild.rs",
36+
rel: "noopener noreferrer",
37+
target: "_blank",
38+
children: "rsbuild"
39+
})]
40+
}), "\\n", _jsxs(_components.h2, {
41+
id: "this-is-link",
42+
children: [_jsx(_components.a, {
43+
className: "rp-header-anchor",
44+
"aria-hidden": "true",
45+
href: "#this-is-link",
46+
children: "#"
47+
}), "this is link ", _jsx(Link, {
48+
href: "https://rsbuild.rs"
49+
})]
50+
}), "\\n", _jsxs(_components.h2, {
51+
id: "this-is-bold-link",
52+
children: [_jsx(_components.a, {
53+
className: "rp-header-anchor",
54+
"aria-hidden": "true",
55+
href: "#this-is-bold-link",
56+
children: "#"
57+
}), "this is bold link ", _jsx(_components.a, {
58+
href: "https://rsbuild.rs",
59+
rel: "noopener noreferrer",
60+
target: "_blank",
61+
children: _jsx(_components.strong, {
62+
children: "rsbuild"
63+
})
64+
})]
65+
}), "\\n", _jsxs(_components.h2, {
66+
id: "this-is-code-link",
67+
children: [_jsx(_components.a, {
68+
className: "rp-header-anchor",
69+
"aria-hidden": "true",
70+
href: "#this-is-code-link",
71+
children: "#"
72+
}), "this is code link ", _jsx(_components.a, {
73+
href: "https://rsbuild.rs",
74+
rel: "noopener noreferrer",
75+
target: "_blank",
76+
children: _jsx(_components.code, {
77+
children: "rsbuild"
78+
})
79+
})]
80+
}), "\\n", _jsxs(_components.h2, {
81+
id: "this-is-bold-code-link",
82+
children: [_jsx(_components.a, {
83+
className: "rp-header-anchor",
84+
"aria-hidden": "true",
85+
href: "#this-is-bold-code-link",
86+
children: "#"
87+
}), "this is bold code link ", _jsx(_components.a, {
88+
href: "https://rsbuild.rs",
89+
rel: "noopener noreferrer",
90+
target: "_blank",
91+
children: _jsx(_components.strong, {
92+
children: _jsx(_components.code, {
93+
children: "rsbuild"
94+
})
95+
})
96+
})]
97+
})]
98+
});
99+
}
100+
export default function MDXContent(props = {}) {
101+
const {wrapper: MDXLayout} = {
102+
..._provideComponents(),
103+
...props.components
104+
};
105+
return MDXLayout ? _jsx(MDXLayout, {
106+
...props,
107+
children: _jsx(_createMdxContent, {
108+
...props
109+
})
110+
}) : _createMdxContent(props);
111+
}
112+
113+
114+
MDXContent.__RSPRESS_PAGE_META = {};
115+
MDXContent.__RSPRESS_PAGE_META["index.mdx"] = {"toc":[{"id":"this-is-link-rsbuild","text":"this is link rsbuild","depth":2},{"id":"this-is-link","text":"this is link","depth":2},{"id":"this-is-bold-link-rsbuild","text":"this is bold link **rsbuild**","depth":2},{"id":"this-is-code-link-rsbuild","text":"this is code link \`rsbuild\`","depth":2},{"id":"this-is-bold-code-link-rsbuild","text":"this is bold code link **\`rsbuild\`**","depth":2}],"title":"link","headingTitle":"link","frontmatter":{}};
116+
"
117+
`;

0 commit comments

Comments
 (0)