@rspress/plugin-api-docgen 2.0.0-beta.1 → 2.0.0-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +28 -28
- package/package.json +12 -9
- package/static/global-components/API.tsx +92 -0
package/README.md
CHANGED
package/dist/index.js
CHANGED
@@ -8,20 +8,20 @@ __WEBPACK_EXTERNAL_MODULE_node_path_c5b9b54f__["default"].join(__dirname, '..');
|
|
8
8
|
const apiDocMap = {};
|
9
9
|
const locales = {
|
10
10
|
zh: {
|
11
|
-
copy:
|
12
|
-
copied:
|
13
|
-
expand:
|
14
|
-
collapse:
|
15
|
-
className:
|
16
|
-
style:
|
17
|
-
children:
|
18
|
-
disabled:
|
19
|
-
required:
|
20
|
-
property:
|
21
|
-
description:
|
22
|
-
type:
|
23
|
-
defaultValue:
|
24
|
-
overview:
|
11
|
+
copy: "\u590D\u5236",
|
12
|
+
copied: "\u590D\u5236\u6210\u529F",
|
13
|
+
expand: "\u5C55\u5F00\u4EE3\u7801",
|
14
|
+
collapse: "\u6536\u8D77\u4EE3\u7801",
|
15
|
+
className: "\u8282\u70B9\u7C7B\u540D",
|
16
|
+
style: "\u8282\u70B9\u6837\u5F0F",
|
17
|
+
children: "\u5B50\u8282\u70B9",
|
18
|
+
disabled: "\u662F\u5426\u7981\u7528",
|
19
|
+
required: "\u5FC5\u586B",
|
20
|
+
property: "\u5C5E\u6027",
|
21
|
+
description: "\u8BF4\u660E",
|
22
|
+
type: "\u7C7B\u578B",
|
23
|
+
defaultValue: "\u9ED8\u8BA4\u503C",
|
24
|
+
overview: "\u6982\u89C8"
|
25
25
|
},
|
26
26
|
en: {
|
27
27
|
copy: 'Copy',
|
@@ -40,20 +40,20 @@ const locales = {
|
|
40
40
|
overview: 'Overview'
|
41
41
|
},
|
42
42
|
ru: {
|
43
|
-
copy:
|
44
|
-
copied:
|
45
|
-
expand:
|
46
|
-
collapse:
|
47
|
-
className:
|
48
|
-
style:
|
49
|
-
children:
|
50
|
-
disabled:
|
51
|
-
required:
|
52
|
-
property:
|
53
|
-
description:
|
54
|
-
type:
|
55
|
-
defaultValue:
|
56
|
-
overview:
|
43
|
+
copy: "\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C",
|
44
|
+
copied: "\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E \u0443\u0441\u043F\u0435\u0448\u043D\u043E",
|
45
|
+
expand: "\u0420\u0430\u0437\u0432\u0435\u0440\u043D\u0443\u0442\u044C \u043A\u043E\u0434",
|
46
|
+
collapse: "\u0421\u0432\u0435\u0440\u043D\u0443\u0442\u044C \u043A\u043E\u0434",
|
47
|
+
className: "\u0418\u043C\u044F \u043A\u043B\u0430\u0441\u0441\u0430 \u0443\u0437\u043B\u0430",
|
48
|
+
style: "\u0421\u0442\u0438\u043B\u044C \u0443\u0437\u043B\u0430",
|
49
|
+
children: "\u0414\u043E\u0447\u0435\u0440\u043D\u0438\u0435 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u044B",
|
50
|
+
disabled: "\u041E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u043E",
|
51
|
+
required: "\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E",
|
52
|
+
property: "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u043E",
|
53
|
+
description: "\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
|
54
|
+
type: "\u0422\u0438\u043F",
|
55
|
+
defaultValue: "\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E",
|
56
|
+
overview: "\u041E\u0431\u0437\u043E\u0440"
|
57
57
|
}
|
58
58
|
};
|
59
59
|
const isToolEntries = (obj)=>!!obj.documentation || !!obj["react-docgen-typescript"];
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@rspress/plugin-api-docgen",
|
3
|
-
"version": "2.0.0-beta.
|
3
|
+
"version": "2.0.0-beta.10",
|
4
4
|
"description": "A plugin for rspress to generate api doc.",
|
5
5
|
"bugs": "https://github.com/web-infra-dev/rspress/issues",
|
6
6
|
"repository": {
|
@@ -25,27 +25,30 @@
|
|
25
25
|
"dependencies": {
|
26
26
|
"chokidar": "^3.6.0",
|
27
27
|
"documentation": "14.0.3",
|
28
|
+
"github-slugger": "^2.0.0",
|
28
29
|
"react-docgen-typescript": "2.2.2",
|
29
30
|
"react-markdown": "^10.1.0",
|
30
31
|
"remark-gfm": "^4.0.1",
|
31
32
|
"unified": "^11.0.5",
|
32
|
-
"
|
33
|
+
"unist-util-visit": "^5.0.0",
|
34
|
+
"@rspress/shared": "2.0.0-beta.10"
|
33
35
|
},
|
34
36
|
"devDependencies": {
|
35
|
-
"@microsoft/api-extractor": "^7.52.
|
36
|
-
"@rslib/core": "0.
|
37
|
+
"@microsoft/api-extractor": "^7.52.8",
|
38
|
+
"@rslib/core": "0.8.0",
|
39
|
+
"@types/hast": "^3.0.4",
|
37
40
|
"@types/mdast": "^4.0.4",
|
38
|
-
"@types/node": "^
|
39
|
-
"@types/react": "^18.3.
|
40
|
-
"@types/react-dom": "^18.3.
|
41
|
+
"@types/node": "^22.8.1",
|
42
|
+
"@types/react": "^18.3.22",
|
43
|
+
"@types/react-dom": "^18.3.7",
|
41
44
|
"react": "^19.1.0",
|
42
45
|
"react-dom": "^19.1.0",
|
43
46
|
"react-router-dom": "^6.29.0",
|
44
|
-
"rsbuild-plugin-publint": "^0.3.
|
47
|
+
"rsbuild-plugin-publint": "^0.3.2",
|
45
48
|
"typescript": "^5.8.2"
|
46
49
|
},
|
47
50
|
"peerDependencies": {
|
48
|
-
"@rspress/core": "^2.0.0-beta.
|
51
|
+
"@rspress/core": "^2.0.0-beta.10",
|
49
52
|
"typescript": "^5.8.2"
|
50
53
|
},
|
51
54
|
"peerDependenciesMeta": {
|
@@ -5,6 +5,97 @@ import { getCustomMDXComponent } from '@rspress/core/theme';
|
|
5
5
|
import ReactMarkdown from 'react-markdown';
|
6
6
|
import remarkGfm from 'remark-gfm';
|
7
7
|
import './API.css';
|
8
|
+
import GithubSlugger from 'github-slugger';
|
9
|
+
import type { Content, Element, Root } from 'hast';
|
10
|
+
// biome-ignore lint/style/useImportType: <exact>
|
11
|
+
import React from 'react';
|
12
|
+
import type { Plugin } from 'unified';
|
13
|
+
import { visit } from 'unist-util-visit';
|
14
|
+
|
15
|
+
function headingRank(node: Root | Content): number | null {
|
16
|
+
const name =
|
17
|
+
(node && node.type === 'element' && node.tagName.toLowerCase()) || '';
|
18
|
+
const code =
|
19
|
+
name.length === 2 && name.charCodeAt(0) === 104 /* `h` */
|
20
|
+
? name.charCodeAt(1)
|
21
|
+
: 0;
|
22
|
+
return code > 48 /* `0` */ && code < 55 /* `7` */
|
23
|
+
? code - 48 /* `0` */
|
24
|
+
: null;
|
25
|
+
}
|
26
|
+
|
27
|
+
const rehypeHeaderAnchor: Plugin<[], Root> = () => {
|
28
|
+
const slugger = new GithubSlugger();
|
29
|
+
return tree => {
|
30
|
+
visit(tree, 'element', node => {
|
31
|
+
if (!headingRank(node)) {
|
32
|
+
return;
|
33
|
+
}
|
34
|
+
// generate id
|
35
|
+
|
36
|
+
if (!node.properties?.id) {
|
37
|
+
const text = collectHeaderText(node);
|
38
|
+
node.properties ??= {};
|
39
|
+
node.properties.id = slugger.slug(text);
|
40
|
+
}
|
41
|
+
// apply to headings
|
42
|
+
node.children.unshift(create(node));
|
43
|
+
});
|
44
|
+
};
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* Create an `a`.
|
49
|
+
*
|
50
|
+
* @param {Readonly<Element>} node
|
51
|
+
* Related heading.
|
52
|
+
* @returns {Element}
|
53
|
+
* Link.
|
54
|
+
*/
|
55
|
+
function create(node: Element): Element {
|
56
|
+
return {
|
57
|
+
type: 'element',
|
58
|
+
tagName: 'a',
|
59
|
+
properties: {
|
60
|
+
class: 'header-anchor',
|
61
|
+
ariaHidden: 'true',
|
62
|
+
href: `#${node.properties!.id}`,
|
63
|
+
},
|
64
|
+
children: [
|
65
|
+
{
|
66
|
+
type: 'text',
|
67
|
+
value: '#',
|
68
|
+
},
|
69
|
+
],
|
70
|
+
};
|
71
|
+
}
|
72
|
+
|
73
|
+
const extractTextAndId = (title?: string): string => {
|
74
|
+
if (!title) {
|
75
|
+
return '';
|
76
|
+
}
|
77
|
+
const text = title.trimEnd();
|
78
|
+
return text;
|
79
|
+
};
|
80
|
+
|
81
|
+
const collectHeaderText = (node: Element): string => {
|
82
|
+
let text = '';
|
83
|
+
node.children.forEach(child => {
|
84
|
+
if (child.type === 'text') {
|
85
|
+
const textPart = extractTextAndId(child.value);
|
86
|
+
child.value = textPart;
|
87
|
+
text += textPart;
|
88
|
+
}
|
89
|
+
if (child.type === 'element') {
|
90
|
+
child.children.forEach(c => {
|
91
|
+
if (c.type === 'text') {
|
92
|
+
text += c.value;
|
93
|
+
}
|
94
|
+
});
|
95
|
+
}
|
96
|
+
});
|
97
|
+
return text;
|
98
|
+
};
|
8
99
|
|
9
100
|
export default (props: { moduleName: string }) => {
|
10
101
|
const lang = useLang();
|
@@ -19,6 +110,7 @@ export default (props: { moduleName: string }) => {
|
|
19
110
|
<div className="rspress-plugin-api-docgen">
|
20
111
|
<ReactMarkdown
|
21
112
|
remarkPlugins={[[remarkGfm]]}
|
113
|
+
rehypePlugins={[[rehypeHeaderAnchor]]}
|
22
114
|
components={
|
23
115
|
getCustomMDXComponent() as Record<string, React.ElementType>
|
24
116
|
}
|