fumadocs-core 16.0.7 → 16.0.9
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/dist/breadcrumb.js +3 -3
- package/dist/chunk-A4G5V4FQ.js +47 -0
- package/dist/chunk-ADBHPKXG.js +78 -0
- package/dist/chunk-CH7YHH7V.js +222 -0
- package/dist/chunk-EFVXL2PP.js +144 -0
- package/dist/chunk-FUUVPEA5.js +29 -0
- package/dist/chunk-GLRQBLGN.js +59 -0
- package/dist/{chunk-JD3M54YF.js → chunk-HNZEUF6C.js} +4 -47
- package/dist/chunk-JOXPHQ2R.js +73 -0
- package/dist/chunk-ONG4RVCR.js +8 -0
- package/dist/chunk-SLIKY7GW.js +111 -0
- package/dist/chunk-TWIDBWFG.js +84 -0
- package/dist/chunk-VW3XKOZZ.js +214 -0
- package/dist/chunk-X2HFD5QJ.js +275 -0
- package/dist/chunk-XJ6ZQNEX.js +91 -0
- package/dist/content/github.d.ts +7 -1
- package/dist/content/github.js +2 -1
- package/dist/content/toc.js +2 -1
- package/dist/mdx-plugins/codeblock-utils.d.ts +29 -0
- package/dist/mdx-plugins/codeblock-utils.js +9 -0
- package/dist/mdx-plugins/index.d.ts +18 -247
- package/dist/mdx-plugins/index.js +42 -1326
- package/dist/mdx-plugins/rehype-code.d.ts +55 -0
- package/dist/mdx-plugins/rehype-code.js +15 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +14 -0
- package/dist/mdx-plugins/rehype-toc.js +7 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +18 -0
- package/dist/mdx-plugins/remark-admonition.js +8 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +30 -0
- package/dist/mdx-plugins/remark-code-tab.js +8 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +1 -0
- package/dist/mdx-plugins/remark-gfm.js +7 -0
- package/dist/mdx-plugins/remark-heading.d.ts +31 -0
- package/dist/mdx-plugins/remark-heading.js +8 -0
- package/dist/mdx-plugins/remark-image.d.ts +57 -0
- package/dist/mdx-plugins/remark-image.js +7 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +40 -0
- package/dist/mdx-plugins/remark-mdx-files.js +7 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +15 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +7 -0
- package/dist/mdx-plugins/remark-npm.d.ts +31 -0
- package/dist/mdx-plugins/remark-npm.js +8 -0
- package/dist/mdx-plugins/remark-steps.d.ts +23 -0
- package/dist/mdx-plugins/remark-steps.js +7 -0
- package/dist/{remark-structure-BJxaB5zZ.d.ts → mdx-plugins/remark-structure.d.ts} +1 -1
- package/dist/mdx-plugins/remark-structure.js +10 -0
- package/dist/{orama-cloud-WEGQE5A6.js → orama-cloud-UZAPMPFV.js} +0 -1
- package/dist/search/algolia.d.ts +1 -1
- package/dist/search/client.d.ts +1 -1
- package/dist/search/client.js +1 -1
- package/dist/search/orama-cloud.d.ts +3 -2
- package/dist/search/server.d.ts +1 -1
- package/dist/search/server.js +3 -3
- package/dist/source/index.js +3 -3
- package/package.json +11 -7
- package/dist/remark-code-tab-DmyIyi6m.d.ts +0 -57
package/dist/breadcrumb.js
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// src/mdx-plugins/mdast-utils.ts
|
|
2
|
+
import { valueToEstree } from "estree-util-value-to-estree";
|
|
3
|
+
function flattenNode(node) {
|
|
4
|
+
if ("children" in node)
|
|
5
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
6
|
+
if ("value" in node) return node.value;
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
function toMdxExport(name, value) {
|
|
10
|
+
return {
|
|
11
|
+
type: "mdxjsEsm",
|
|
12
|
+
value: "",
|
|
13
|
+
data: {
|
|
14
|
+
estree: {
|
|
15
|
+
type: "Program",
|
|
16
|
+
sourceType: "module",
|
|
17
|
+
body: [
|
|
18
|
+
{
|
|
19
|
+
type: "ExportNamedDeclaration",
|
|
20
|
+
attributes: [],
|
|
21
|
+
specifiers: [],
|
|
22
|
+
source: null,
|
|
23
|
+
declaration: {
|
|
24
|
+
type: "VariableDeclaration",
|
|
25
|
+
kind: "let",
|
|
26
|
+
declarations: [
|
|
27
|
+
{
|
|
28
|
+
type: "VariableDeclarator",
|
|
29
|
+
id: {
|
|
30
|
+
type: "Identifier",
|
|
31
|
+
name
|
|
32
|
+
},
|
|
33
|
+
init: valueToEstree(value)
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export {
|
|
45
|
+
flattenNode,
|
|
46
|
+
toMdxExport
|
|
47
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// src/mdx-plugins/remark-mdx-files.ts
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
function parseFileTree(code) {
|
|
4
|
+
const lines = code.split(/\r?\n/);
|
|
5
|
+
const stack = /* @__PURE__ */ new Map();
|
|
6
|
+
for (const line of lines) {
|
|
7
|
+
let depth = 0;
|
|
8
|
+
let name = line;
|
|
9
|
+
let match;
|
|
10
|
+
while (match = /(?:├──|│|└──)\s*/.exec(name)) {
|
|
11
|
+
name = name.slice(match[0].length);
|
|
12
|
+
depth++;
|
|
13
|
+
}
|
|
14
|
+
if (!name) continue;
|
|
15
|
+
const node = name.endsWith("/") ? { type: "folder", name, children: [], depth } : { type: "file", name, depth };
|
|
16
|
+
let parent;
|
|
17
|
+
for (let i = depth - 1; i >= 0 && !parent; i--) {
|
|
18
|
+
parent = stack.get(i);
|
|
19
|
+
}
|
|
20
|
+
stack.set(depth, node);
|
|
21
|
+
if (!parent) continue;
|
|
22
|
+
if (parent.type === "file") {
|
|
23
|
+
Object.assign(parent, {
|
|
24
|
+
type: "folder",
|
|
25
|
+
children: []
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
parent.children.push(node);
|
|
29
|
+
}
|
|
30
|
+
return stack.get(0);
|
|
31
|
+
}
|
|
32
|
+
function defaultToMDX(node, depth = 0) {
|
|
33
|
+
if (depth === 0) {
|
|
34
|
+
return {
|
|
35
|
+
type: "mdxJsxFlowElement",
|
|
36
|
+
name: "Files",
|
|
37
|
+
attributes: [],
|
|
38
|
+
children: [defaultToMDX(node, depth + 1)]
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const attributes = [
|
|
42
|
+
{ type: "mdxJsxAttribute", name: "name", value: node.name }
|
|
43
|
+
];
|
|
44
|
+
if (node.type === "file") {
|
|
45
|
+
return {
|
|
46
|
+
type: "mdxJsxFlowElement",
|
|
47
|
+
attributes,
|
|
48
|
+
children: [],
|
|
49
|
+
name: "File"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
attributes.push({
|
|
53
|
+
type: "mdxJsxAttribute",
|
|
54
|
+
name: "defaultOpen",
|
|
55
|
+
value: null
|
|
56
|
+
});
|
|
57
|
+
return {
|
|
58
|
+
type: "mdxJsxFlowElement",
|
|
59
|
+
attributes,
|
|
60
|
+
name: "Folder",
|
|
61
|
+
children: node.children.map((item) => defaultToMDX(item, depth + 1))
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function remarkMdxFiles(options = {}) {
|
|
65
|
+
const { lang = "files", toMdx = defaultToMDX } = options;
|
|
66
|
+
return (tree) => {
|
|
67
|
+
visit(tree, "code", (node) => {
|
|
68
|
+
if (node.lang !== lang || !node.value) return;
|
|
69
|
+
const fileTree = parseFileTree(node.value);
|
|
70
|
+
if (!fileTree) return;
|
|
71
|
+
Object.assign(node, toMdx(fileTree));
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export {
|
|
77
|
+
remarkMdxFiles
|
|
78
|
+
};
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCodeBlockTabs,
|
|
3
|
+
parseCodeBlockAttributes
|
|
4
|
+
} from "./chunk-TWIDBWFG.js";
|
|
5
|
+
|
|
6
|
+
// src/mdx-plugins/remark-code-tab.ts
|
|
7
|
+
import { visit } from "unist-util-visit";
|
|
8
|
+
var Tabs = {
|
|
9
|
+
convert(processor, nodes, withMdx = false, withParent = true) {
|
|
10
|
+
const tabs = Array.from(processTabValue(nodes).entries());
|
|
11
|
+
if (!withMdx) {
|
|
12
|
+
const children2 = tabs.map(([name, codes]) => {
|
|
13
|
+
return {
|
|
14
|
+
type: "mdxJsxFlowElement",
|
|
15
|
+
name: "Tab",
|
|
16
|
+
attributes: [
|
|
17
|
+
{
|
|
18
|
+
type: "mdxJsxAttribute",
|
|
19
|
+
name: "value",
|
|
20
|
+
value: name
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
children: codes
|
|
24
|
+
};
|
|
25
|
+
});
|
|
26
|
+
if (!withParent) return createFragment(children2);
|
|
27
|
+
return {
|
|
28
|
+
type: "mdxJsxFlowElement",
|
|
29
|
+
name: "Tabs",
|
|
30
|
+
attributes: [
|
|
31
|
+
{
|
|
32
|
+
type: "mdxJsxAttribute",
|
|
33
|
+
name: "items",
|
|
34
|
+
value: {
|
|
35
|
+
type: "mdxJsxAttributeValueExpression",
|
|
36
|
+
value: tabs.map(([name]) => name).join(", "),
|
|
37
|
+
data: {
|
|
38
|
+
estree: {
|
|
39
|
+
type: "Program",
|
|
40
|
+
sourceType: "module",
|
|
41
|
+
comments: [],
|
|
42
|
+
body: [
|
|
43
|
+
{
|
|
44
|
+
type: "ExpressionStatement",
|
|
45
|
+
expression: {
|
|
46
|
+
type: "ArrayExpression",
|
|
47
|
+
elements: tabs.map(([name]) => ({
|
|
48
|
+
type: "Literal",
|
|
49
|
+
value: name
|
|
50
|
+
}))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
children: children2
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
const children = [
|
|
63
|
+
{
|
|
64
|
+
type: "mdxJsxFlowElement",
|
|
65
|
+
name: "TabsList",
|
|
66
|
+
attributes: [],
|
|
67
|
+
children: tabs.map(([name]) => ({
|
|
68
|
+
type: "mdxJsxFlowElement",
|
|
69
|
+
name: "TabsTrigger",
|
|
70
|
+
attributes: [
|
|
71
|
+
{
|
|
72
|
+
type: "mdxJsxAttribute",
|
|
73
|
+
name: "value",
|
|
74
|
+
value: name
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
children: [mdxToAst(processor, name)]
|
|
78
|
+
}))
|
|
79
|
+
},
|
|
80
|
+
...tabs.map(
|
|
81
|
+
([name, codes]) => ({
|
|
82
|
+
type: "mdxJsxFlowElement",
|
|
83
|
+
name: "TabsContent",
|
|
84
|
+
attributes: [
|
|
85
|
+
{
|
|
86
|
+
type: "mdxJsxAttribute",
|
|
87
|
+
name: "value",
|
|
88
|
+
value: name
|
|
89
|
+
}
|
|
90
|
+
],
|
|
91
|
+
children: codes
|
|
92
|
+
})
|
|
93
|
+
)
|
|
94
|
+
];
|
|
95
|
+
if (!withParent) return createFragment(children);
|
|
96
|
+
return {
|
|
97
|
+
type: "mdxJsxFlowElement",
|
|
98
|
+
name: "Tabs",
|
|
99
|
+
attributes: [
|
|
100
|
+
{
|
|
101
|
+
type: "mdxJsxAttribute",
|
|
102
|
+
name: "defaultValue",
|
|
103
|
+
value: tabs[0][0]
|
|
104
|
+
}
|
|
105
|
+
],
|
|
106
|
+
children
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
var CodeBlockTabs = {
|
|
111
|
+
convert(processor, nodes, withMdx = false, withParent = true) {
|
|
112
|
+
const tabs = Array.from(processTabValue(nodes).entries());
|
|
113
|
+
const node = generateCodeBlockTabs({
|
|
114
|
+
defaultValue: tabs[0][0],
|
|
115
|
+
triggers: tabs.map(([name]) => ({
|
|
116
|
+
value: name,
|
|
117
|
+
children: [
|
|
118
|
+
withMdx ? mdxToAst(processor, name) : {
|
|
119
|
+
type: "text",
|
|
120
|
+
value: name
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
})),
|
|
124
|
+
tabs: tabs.map(([name, codes]) => ({
|
|
125
|
+
value: name,
|
|
126
|
+
children: codes
|
|
127
|
+
}))
|
|
128
|
+
});
|
|
129
|
+
if (!withParent) return createFragment(node.children);
|
|
130
|
+
return node;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
var Types = {
|
|
134
|
+
CodeBlockTabs,
|
|
135
|
+
Tabs
|
|
136
|
+
};
|
|
137
|
+
function remarkCodeTab(options = {}) {
|
|
138
|
+
const { parseMdx = false, Tabs: Tabs2 = "CodeBlockTabs" } = options;
|
|
139
|
+
return (tree) => {
|
|
140
|
+
const ignored = /* @__PURE__ */ new WeakSet();
|
|
141
|
+
visit(tree, (node) => {
|
|
142
|
+
if (!("children" in node) || ignored.has(node)) return "skip";
|
|
143
|
+
let localTabs = Tabs2;
|
|
144
|
+
let localParseMdx = parseMdx;
|
|
145
|
+
let withParent = true;
|
|
146
|
+
if (node.type === "mdxJsxFlowElement" && node.name && node.name in Types) {
|
|
147
|
+
withParent = false;
|
|
148
|
+
localTabs = node.name;
|
|
149
|
+
if (node.name === "Tabs" && localParseMdx) {
|
|
150
|
+
localParseMdx = node.attributes.every(
|
|
151
|
+
(attribute) => attribute.type !== "mdxJsxAttribute" || attribute.name !== "items"
|
|
152
|
+
);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
let start = -1;
|
|
156
|
+
let end = 0;
|
|
157
|
+
const close = () => {
|
|
158
|
+
if (start === -1 || start === end) return;
|
|
159
|
+
const replacement = Types[localTabs].convert(
|
|
160
|
+
this,
|
|
161
|
+
node.children.slice(start, end),
|
|
162
|
+
localParseMdx,
|
|
163
|
+
withParent
|
|
164
|
+
);
|
|
165
|
+
ignored.add(replacement);
|
|
166
|
+
node.children.splice(start, end - start, replacement);
|
|
167
|
+
end = start;
|
|
168
|
+
start = -1;
|
|
169
|
+
};
|
|
170
|
+
for (; end < node.children.length; end++) {
|
|
171
|
+
const child = node.children[end];
|
|
172
|
+
if (child.type !== "code" || !child.meta) {
|
|
173
|
+
close();
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const meta = parseCodeBlockAttributes(child.meta, ["tab"]);
|
|
177
|
+
if (!meta.attributes.tab) {
|
|
178
|
+
close();
|
|
179
|
+
continue;
|
|
180
|
+
}
|
|
181
|
+
if (start === -1) start = end;
|
|
182
|
+
child.meta = meta.rest;
|
|
183
|
+
child.data ??= {};
|
|
184
|
+
child.data.tab = meta.attributes.tab;
|
|
185
|
+
}
|
|
186
|
+
close();
|
|
187
|
+
});
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function processTabValue(nodes) {
|
|
191
|
+
const out = /* @__PURE__ */ new Map();
|
|
192
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
193
|
+
const node = nodes[i];
|
|
194
|
+
const name = node.data?.tab ?? `Tab ${i + 1}`;
|
|
195
|
+
const li = out.get(name) ?? [];
|
|
196
|
+
li.push(node);
|
|
197
|
+
out.set(name, li);
|
|
198
|
+
}
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
function mdxToAst(processor, name) {
|
|
202
|
+
const node = processor.parse(name);
|
|
203
|
+
if (node.type === "root") {
|
|
204
|
+
node.children = node.children.flatMap((child) => {
|
|
205
|
+
if (child.type === "paragraph") return child.children;
|
|
206
|
+
return child;
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return node;
|
|
210
|
+
}
|
|
211
|
+
function createFragment(children) {
|
|
212
|
+
return {
|
|
213
|
+
type: "mdxJsxFlowElement",
|
|
214
|
+
name: null,
|
|
215
|
+
attributes: [],
|
|
216
|
+
children
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
export {
|
|
221
|
+
remarkCodeTab
|
|
222
|
+
};
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
// src/mdx-plugins/rehype-toc.ts
|
|
2
|
+
import { toEstree } from "hast-util-to-estree";
|
|
3
|
+
|
|
4
|
+
// src/mdx-plugins/hast-utils.ts
|
|
5
|
+
function visit(node, tagNames, handler) {
|
|
6
|
+
if (node.type === "element" && tagNames.includes(node.tagName)) {
|
|
7
|
+
const result = handler(node);
|
|
8
|
+
if (result === "skip") return;
|
|
9
|
+
}
|
|
10
|
+
if ("children" in node)
|
|
11
|
+
node.children.forEach((n) => {
|
|
12
|
+
visit(n, tagNames, handler);
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// src/mdx-plugins/rehype-toc.ts
|
|
17
|
+
var TocOnlyTag = "[toc]";
|
|
18
|
+
var NoTocTag = "[!toc]";
|
|
19
|
+
function rehypeToc({ exportToc = true } = {}) {
|
|
20
|
+
return (tree) => {
|
|
21
|
+
const output = [];
|
|
22
|
+
visit(tree, ["h1", "h2", "h3", "h4", "h5", "h6"], (element) => {
|
|
23
|
+
const id = element.properties.id;
|
|
24
|
+
if (typeof id !== "string") return "skip";
|
|
25
|
+
let isTocOnly = false;
|
|
26
|
+
const last = element.children.at(-1);
|
|
27
|
+
if (last?.type === "text" && last.value.endsWith(TocOnlyTag)) {
|
|
28
|
+
isTocOnly = true;
|
|
29
|
+
last.value = last.value.substring(0, last.value.length - TocOnlyTag.length).trimEnd();
|
|
30
|
+
} else if (last?.type === "text" && last.value.endsWith(NoTocTag)) {
|
|
31
|
+
last.value = last.value.substring(0, last.value.length - NoTocTag.length).trimEnd();
|
|
32
|
+
return "skip";
|
|
33
|
+
}
|
|
34
|
+
const estree = toEstree(element, {
|
|
35
|
+
elementAttributeNameCase: "react",
|
|
36
|
+
stylePropertyNameCase: "dom"
|
|
37
|
+
});
|
|
38
|
+
if (estree.body[0].type === "ExpressionStatement")
|
|
39
|
+
output.push({
|
|
40
|
+
title: estree.body[0].expression,
|
|
41
|
+
depth: Number(element.tagName.slice(1)),
|
|
42
|
+
url: `#${id}`
|
|
43
|
+
});
|
|
44
|
+
if (isTocOnly) {
|
|
45
|
+
Object.assign(element, {
|
|
46
|
+
type: "comment",
|
|
47
|
+
value: ""
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return "skip";
|
|
51
|
+
});
|
|
52
|
+
const declaration = {
|
|
53
|
+
type: "VariableDeclaration",
|
|
54
|
+
kind: "const",
|
|
55
|
+
declarations: [
|
|
56
|
+
{
|
|
57
|
+
type: "VariableDeclarator",
|
|
58
|
+
id: {
|
|
59
|
+
type: "Identifier",
|
|
60
|
+
name: "toc"
|
|
61
|
+
},
|
|
62
|
+
init: {
|
|
63
|
+
type: "ArrayExpression",
|
|
64
|
+
elements: output.map((item) => ({
|
|
65
|
+
type: "ObjectExpression",
|
|
66
|
+
properties: [
|
|
67
|
+
{
|
|
68
|
+
type: "Property",
|
|
69
|
+
method: false,
|
|
70
|
+
shorthand: false,
|
|
71
|
+
computed: false,
|
|
72
|
+
key: {
|
|
73
|
+
type: "Identifier",
|
|
74
|
+
name: "depth"
|
|
75
|
+
},
|
|
76
|
+
value: {
|
|
77
|
+
type: "Literal",
|
|
78
|
+
value: item.depth
|
|
79
|
+
},
|
|
80
|
+
kind: "init"
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
type: "Property",
|
|
84
|
+
method: false,
|
|
85
|
+
shorthand: false,
|
|
86
|
+
computed: false,
|
|
87
|
+
key: {
|
|
88
|
+
type: "Identifier",
|
|
89
|
+
name: "url"
|
|
90
|
+
},
|
|
91
|
+
value: {
|
|
92
|
+
type: "Literal",
|
|
93
|
+
value: item.url
|
|
94
|
+
},
|
|
95
|
+
kind: "init"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
type: "Property",
|
|
99
|
+
method: false,
|
|
100
|
+
shorthand: false,
|
|
101
|
+
computed: false,
|
|
102
|
+
key: {
|
|
103
|
+
type: "Identifier",
|
|
104
|
+
name: "title"
|
|
105
|
+
},
|
|
106
|
+
value: {
|
|
107
|
+
type: "JSXFragment",
|
|
108
|
+
openingFragment: { type: "JSXOpeningFragment" },
|
|
109
|
+
closingFragment: { type: "JSXClosingFragment" },
|
|
110
|
+
children: item.title.children
|
|
111
|
+
},
|
|
112
|
+
kind: "init"
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
}))
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
]
|
|
119
|
+
};
|
|
120
|
+
tree.children.push({
|
|
121
|
+
type: "mdxjsEsm",
|
|
122
|
+
value: "",
|
|
123
|
+
data: {
|
|
124
|
+
estree: {
|
|
125
|
+
type: "Program",
|
|
126
|
+
body: [
|
|
127
|
+
exportToc ? {
|
|
128
|
+
type: "ExportNamedDeclaration",
|
|
129
|
+
declaration,
|
|
130
|
+
attributes: [],
|
|
131
|
+
specifiers: []
|
|
132
|
+
} : declaration
|
|
133
|
+
],
|
|
134
|
+
sourceType: "module",
|
|
135
|
+
comments: []
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export {
|
|
143
|
+
rehypeToc
|
|
144
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// src/mdx-plugins/remark-mdx-mermaid.ts
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
function toMDX(code) {
|
|
4
|
+
return {
|
|
5
|
+
type: "mdxJsxFlowElement",
|
|
6
|
+
name: "Mermaid",
|
|
7
|
+
attributes: [
|
|
8
|
+
{
|
|
9
|
+
type: "mdxJsxAttribute",
|
|
10
|
+
name: "chart",
|
|
11
|
+
value: code.trim()
|
|
12
|
+
}
|
|
13
|
+
],
|
|
14
|
+
children: []
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function remarkMdxMermaid(options = {}) {
|
|
18
|
+
const { lang = "mermaid" } = options;
|
|
19
|
+
return (tree) => {
|
|
20
|
+
visit(tree, "code", (node) => {
|
|
21
|
+
if (node.lang !== lang || !node.value) return;
|
|
22
|
+
Object.assign(node, toMDX(node.value));
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
remarkMdxMermaid
|
|
29
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCodeBlockTabs
|
|
3
|
+
} from "./chunk-TWIDBWFG.js";
|
|
4
|
+
|
|
5
|
+
// src/mdx-plugins/remark-npm.ts
|
|
6
|
+
import { visit } from "unist-util-visit";
|
|
7
|
+
import convert from "npm-to-yarn";
|
|
8
|
+
var aliases = ["npm", "package-install"];
|
|
9
|
+
function remarkNpm({
|
|
10
|
+
persist = false,
|
|
11
|
+
packageManagers = [
|
|
12
|
+
{ command: (cmd) => convert(cmd, "npm"), name: "npm" },
|
|
13
|
+
{ command: (cmd) => convert(cmd, "pnpm"), name: "pnpm" },
|
|
14
|
+
{ command: (cmd) => convert(cmd, "yarn"), name: "yarn" },
|
|
15
|
+
{ command: (cmd) => convert(cmd, "bun"), name: "bun" }
|
|
16
|
+
]
|
|
17
|
+
} = {}) {
|
|
18
|
+
return (tree) => {
|
|
19
|
+
visit(tree, "code", (node) => {
|
|
20
|
+
if (!node.lang || !aliases.includes(node.lang)) return;
|
|
21
|
+
let code = node.value;
|
|
22
|
+
if (node.lang === "package-install" && !code.startsWith("npm") && !code.startsWith("npx")) {
|
|
23
|
+
code = `npm install ${code}`;
|
|
24
|
+
}
|
|
25
|
+
const options = {
|
|
26
|
+
persist,
|
|
27
|
+
tabs: [],
|
|
28
|
+
triggers: []
|
|
29
|
+
};
|
|
30
|
+
for (const manager of packageManagers) {
|
|
31
|
+
const value = manager.value ?? manager.name;
|
|
32
|
+
const command = manager.command(code);
|
|
33
|
+
if (!command || command.length === 0) continue;
|
|
34
|
+
options.defaultValue ??= value;
|
|
35
|
+
options.triggers.push({
|
|
36
|
+
value,
|
|
37
|
+
children: [{ type: "text", value: manager.name }]
|
|
38
|
+
});
|
|
39
|
+
options.tabs.push({
|
|
40
|
+
value,
|
|
41
|
+
children: [
|
|
42
|
+
{
|
|
43
|
+
type: "code",
|
|
44
|
+
lang: "bash",
|
|
45
|
+
meta: node.meta,
|
|
46
|
+
value: command
|
|
47
|
+
}
|
|
48
|
+
]
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
Object.assign(node, generateCodeBlockTabs(options));
|
|
52
|
+
return "skip";
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
remarkNpm
|
|
59
|
+
};
|
|
@@ -1,51 +1,10 @@
|
|
|
1
|
+
import {
|
|
2
|
+
flattenNode
|
|
3
|
+
} from "./chunk-A4G5V4FQ.js";
|
|
4
|
+
|
|
1
5
|
// src/mdx-plugins/remark-heading.ts
|
|
2
6
|
import Slugger from "github-slugger";
|
|
3
7
|
import { visit } from "unist-util-visit";
|
|
4
|
-
|
|
5
|
-
// src/mdx-plugins/mdast-utils.ts
|
|
6
|
-
import { valueToEstree } from "estree-util-value-to-estree";
|
|
7
|
-
function flattenNode(node) {
|
|
8
|
-
if ("children" in node)
|
|
9
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
10
|
-
if ("value" in node) return node.value;
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
function toMdxExport(name, value) {
|
|
14
|
-
return {
|
|
15
|
-
type: "mdxjsEsm",
|
|
16
|
-
value: "",
|
|
17
|
-
data: {
|
|
18
|
-
estree: {
|
|
19
|
-
type: "Program",
|
|
20
|
-
sourceType: "module",
|
|
21
|
-
body: [
|
|
22
|
-
{
|
|
23
|
-
type: "ExportNamedDeclaration",
|
|
24
|
-
attributes: [],
|
|
25
|
-
specifiers: [],
|
|
26
|
-
source: null,
|
|
27
|
-
declaration: {
|
|
28
|
-
type: "VariableDeclaration",
|
|
29
|
-
kind: "let",
|
|
30
|
-
declarations: [
|
|
31
|
-
{
|
|
32
|
-
type: "VariableDeclarator",
|
|
33
|
-
id: {
|
|
34
|
-
type: "Identifier",
|
|
35
|
-
name
|
|
36
|
-
},
|
|
37
|
-
init: valueToEstree(value)
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
]
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// src/mdx-plugins/remark-heading.ts
|
|
49
8
|
var slugger = new Slugger();
|
|
50
9
|
var regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
|
|
51
10
|
function remarkHeading({
|
|
@@ -87,7 +46,5 @@ function remarkHeading({
|
|
|
87
46
|
}
|
|
88
47
|
|
|
89
48
|
export {
|
|
90
|
-
flattenNode,
|
|
91
|
-
toMdxExport,
|
|
92
49
|
remarkHeading
|
|
93
50
|
};
|