fumadocs-mdx 11.6.0 → 13.0.1
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/bin.cjs +1728 -0
- package/dist/bin.d.cts +1 -0
- package/dist/bin.d.ts +1 -0
- package/dist/bin.js +16 -0
- package/dist/build-mdx-CCNr86q6.d.ts +53 -0
- package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
- package/dist/bun/index.cjs +857 -0
- package/dist/bun/index.d.cts +13 -0
- package/dist/bun/index.d.ts +13 -0
- package/dist/bun/index.js +62 -0
- package/dist/chunk-3J3WL7WN.js +160 -0
- package/dist/chunk-CXA4JO4Z.js +45 -0
- package/dist/chunk-EELYB2XC.js +207 -0
- package/dist/chunk-FSZMKRVH.js +80 -0
- package/dist/chunk-II3H5ZVZ.js +77 -0
- package/dist/chunk-JVZFH6ND.js +40 -0
- package/dist/chunk-K5ZLPEIQ.js +207 -0
- package/dist/{chunk-VFALQK6O.js → chunk-KILFIBVW.js} +21 -12
- package/dist/chunk-NVRDCY6Z.js +30 -0
- package/dist/chunk-U4MQ44TS.js +53 -0
- package/dist/chunk-VWJKRQZR.js +19 -0
- package/dist/chunk-XQ5O7IPO.js +128 -0
- package/dist/chunk-XZY2AWJI.js +81 -0
- package/dist/chunk-YVCR6FUH.js +82 -0
- package/dist/config/index.cjs +232 -128
- package/dist/config/index.d.cts +4 -6
- package/dist/config/index.d.ts +4 -6
- package/dist/config/index.js +26 -19
- package/dist/core-B6j6Fxse.d.cts +218 -0
- package/dist/core-B6j6Fxse.d.ts +218 -0
- package/dist/index.cjs +0 -76
- package/dist/index.d.cts +73 -20
- package/dist/index.d.ts +73 -20
- package/dist/index.js +0 -10
- package/dist/load-MNG3CLET.js +7 -0
- package/dist/next/index.cjs +567 -314
- package/dist/next/index.d.cts +9 -12
- package/dist/next/index.d.ts +9 -12
- package/dist/next/index.js +238 -211
- package/dist/node/loader.cjs +922 -0
- package/dist/node/loader.d.cts +5 -0
- package/dist/node/loader.d.ts +5 -0
- package/dist/node/loader.js +33 -0
- package/dist/plugins/json-schema.cjs +162 -0
- package/dist/plugins/json-schema.d.cts +24 -0
- package/dist/plugins/json-schema.d.ts +24 -0
- package/dist/plugins/json-schema.js +78 -0
- package/dist/{mdx-options-CAU273O3.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +715 -0
- package/dist/runtime/next/async.d.cts +21 -0
- package/dist/runtime/next/async.d.ts +21 -0
- package/dist/runtime/next/async.js +89 -0
- package/dist/runtime/next/index.cjs +136 -0
- package/dist/runtime/next/index.d.cts +33 -0
- package/dist/runtime/next/index.d.ts +33 -0
- package/dist/runtime/next/index.js +11 -0
- package/dist/runtime/vite/browser.cjs +107 -0
- package/dist/runtime/vite/browser.d.cts +59 -0
- package/dist/runtime/vite/browser.d.ts +59 -0
- package/dist/runtime/vite/browser.js +11 -0
- package/dist/runtime/vite/server.cjs +243 -0
- package/dist/runtime/vite/server.d.cts +30 -0
- package/dist/runtime/vite/server.d.ts +30 -0
- package/dist/runtime/vite/server.js +111 -0
- package/dist/types-AGzTfBmf.d.ts +45 -0
- package/dist/types-DKGMoay5.d.cts +45 -0
- package/dist/vite/index.cjs +1185 -0
- package/dist/vite/index.d.cts +45 -0
- package/dist/vite/index.d.ts +45 -0
- package/dist/vite/index.js +297 -0
- package/dist/webpack/index.cjs +957 -0
- package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +3 -6
- package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +3 -6
- package/dist/webpack/index.js +44 -0
- package/loader-mdx.cjs +1 -1
- package/package.json +86 -29
- package/bin.js +0 -5
- package/dist/chunk-2ZOW45YZ.js +0 -63
- package/dist/chunk-DRVUBK5B.js +0 -39
- package/dist/chunk-HFLDWPJA.js +0 -62
- package/dist/chunk-IOENRFUX.js +0 -112
- package/dist/chunk-MK7EXW7O.js +0 -75
- package/dist/define-BaW0PQDJ.d.cts +0 -201
- package/dist/define-BaW0PQDJ.d.ts +0 -201
- package/dist/loader-mdx.cjs +0 -527
- package/dist/loader-mdx.js +0 -162
- package/dist/runtime/async.cjs +0 -269
- package/dist/runtime/async.d.cts +0 -18
- package/dist/runtime/async.d.ts +0 -18
- package/dist/runtime/async.js +0 -73
- package/dist/types-BNrQHCj5.d.cts +0 -100
- package/dist/types-DEduCvIT.d.ts +0 -100
- package/dist/watcher-IAZDSTU7.js +0 -24
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __export = (target, all) => {
|
|
12
|
+
for (var name in all)
|
|
13
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
|
+
};
|
|
15
|
+
var __copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
17
|
+
for (let key of __getOwnPropNames(from))
|
|
18
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
19
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
20
|
+
}
|
|
21
|
+
return to;
|
|
22
|
+
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
31
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
|
+
|
|
33
|
+
// src/loaders/mdx/preset.ts
|
|
34
|
+
var preset_exports = {};
|
|
35
|
+
__export(preset_exports, {
|
|
36
|
+
getDefaultMDXOptions: () => getDefaultMDXOptions
|
|
37
|
+
});
|
|
38
|
+
function pluginOption(def, options = []) {
|
|
39
|
+
const list = def(Array.isArray(options) ? options : []).filter(
|
|
40
|
+
Boolean
|
|
41
|
+
);
|
|
42
|
+
if (typeof options === "function") {
|
|
43
|
+
return options(list);
|
|
44
|
+
}
|
|
45
|
+
return list;
|
|
46
|
+
}
|
|
47
|
+
function getDefaultMDXOptions({
|
|
48
|
+
valueToExport = [],
|
|
49
|
+
rehypeCodeOptions,
|
|
50
|
+
remarkImageOptions,
|
|
51
|
+
remarkHeadingOptions,
|
|
52
|
+
remarkStructureOptions,
|
|
53
|
+
remarkCodeTabOptions,
|
|
54
|
+
remarkNpmOptions,
|
|
55
|
+
_withoutBundler = false,
|
|
56
|
+
...mdxOptions
|
|
57
|
+
}) {
|
|
58
|
+
const remarkPlugins = pluginOption(
|
|
59
|
+
(v) => [
|
|
60
|
+
plugins.remarkGfm,
|
|
61
|
+
[
|
|
62
|
+
plugins.remarkHeading,
|
|
63
|
+
{
|
|
64
|
+
generateToc: false,
|
|
65
|
+
...remarkHeadingOptions
|
|
66
|
+
}
|
|
67
|
+
],
|
|
68
|
+
remarkImageOptions !== false && [
|
|
69
|
+
plugins.remarkImage,
|
|
70
|
+
{
|
|
71
|
+
...remarkImageOptions,
|
|
72
|
+
useImport: _withoutBundler ? false : remarkImageOptions?.useImport
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
|
|
76
|
+
plugins.remarkCodeTab,
|
|
77
|
+
remarkCodeTabOptions
|
|
78
|
+
],
|
|
79
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
80
|
+
...v,
|
|
81
|
+
remarkStructureOptions !== false && [
|
|
82
|
+
plugins.remarkStructure,
|
|
83
|
+
remarkStructureOptions
|
|
84
|
+
],
|
|
85
|
+
() => {
|
|
86
|
+
return (_, file) => {
|
|
87
|
+
file.data["mdx-export"] ??= [];
|
|
88
|
+
for (const name of valueToExport) {
|
|
89
|
+
if (name in file.data)
|
|
90
|
+
file.data["mdx-export"].push({ name, value: file.data[name] });
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
],
|
|
95
|
+
mdxOptions.remarkPlugins
|
|
96
|
+
);
|
|
97
|
+
const rehypePlugins = pluginOption(
|
|
98
|
+
(v) => [
|
|
99
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
100
|
+
...v,
|
|
101
|
+
plugins.rehypeToc
|
|
102
|
+
],
|
|
103
|
+
mdxOptions.rehypePlugins
|
|
104
|
+
);
|
|
105
|
+
return {
|
|
106
|
+
...mdxOptions,
|
|
107
|
+
outputFormat: _withoutBundler ? "function-body" : mdxOptions.outputFormat,
|
|
108
|
+
remarkPlugins,
|
|
109
|
+
rehypePlugins
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
var plugins;
|
|
113
|
+
var init_preset = __esm({
|
|
114
|
+
"src/loaders/mdx/preset.ts"() {
|
|
115
|
+
"use strict";
|
|
116
|
+
plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
// src/runtime/next/async.ts
|
|
121
|
+
var async_exports = {};
|
|
122
|
+
__export(async_exports, {
|
|
123
|
+
_runtimeAsync: () => _runtimeAsync,
|
|
124
|
+
buildConfig: () => buildConfig
|
|
125
|
+
});
|
|
126
|
+
module.exports = __toCommonJS(async_exports);
|
|
127
|
+
|
|
128
|
+
// src/runtime/shared.ts
|
|
129
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
130
|
+
function createDocMethods(info, load2) {
|
|
131
|
+
return {
|
|
132
|
+
info,
|
|
133
|
+
async getText(type) {
|
|
134
|
+
if (type === "raw") {
|
|
135
|
+
return (await import_promises.default.readFile(info.fullPath)).toString();
|
|
136
|
+
}
|
|
137
|
+
const data = await load2();
|
|
138
|
+
if (typeof data._markdown !== "string")
|
|
139
|
+
throw new Error(
|
|
140
|
+
"getText('processed') requires `includeProcessedMarkdown` to be enabled in your collection config."
|
|
141
|
+
);
|
|
142
|
+
return data._markdown;
|
|
143
|
+
},
|
|
144
|
+
async getMDAST() {
|
|
145
|
+
const data = await load2();
|
|
146
|
+
if (!data._mdast)
|
|
147
|
+
throw new Error(
|
|
148
|
+
"getMDAST() requires `includeMDAST` to be enabled in your collection config."
|
|
149
|
+
);
|
|
150
|
+
return JSON.parse(data._mdast);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/runtime/next/index.ts
|
|
156
|
+
var _runtime = {
|
|
157
|
+
doc(files) {
|
|
158
|
+
return files.map((file) => {
|
|
159
|
+
const data = file.data;
|
|
160
|
+
return {
|
|
161
|
+
_exports: data,
|
|
162
|
+
body: data.default,
|
|
163
|
+
lastModified: data.lastModified,
|
|
164
|
+
toc: data.toc,
|
|
165
|
+
structuredData: data.structuredData,
|
|
166
|
+
extractedReferences: data.extractedReferences,
|
|
167
|
+
...data.frontmatter,
|
|
168
|
+
...createDocMethods(file.info, () => Promise.resolve(data))
|
|
169
|
+
};
|
|
170
|
+
});
|
|
171
|
+
},
|
|
172
|
+
meta(files) {
|
|
173
|
+
return files.map((file) => {
|
|
174
|
+
return {
|
|
175
|
+
info: file.info,
|
|
176
|
+
...file.data
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
docs(docs, metas) {
|
|
181
|
+
const parsedDocs = this.doc(docs);
|
|
182
|
+
const parsedMetas = this.meta(metas);
|
|
183
|
+
return {
|
|
184
|
+
docs: parsedDocs,
|
|
185
|
+
meta: parsedMetas,
|
|
186
|
+
toFumadocsSource() {
|
|
187
|
+
return createMDXSource(parsedDocs, parsedMetas);
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
function createMDXSource(docs, meta = []) {
|
|
193
|
+
return {
|
|
194
|
+
files: resolveFiles({
|
|
195
|
+
docs,
|
|
196
|
+
meta
|
|
197
|
+
})
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
function resolveFiles({ docs, meta }) {
|
|
201
|
+
const outputs = [];
|
|
202
|
+
for (const entry of docs) {
|
|
203
|
+
outputs.push({
|
|
204
|
+
type: "page",
|
|
205
|
+
absolutePath: entry.info.fullPath,
|
|
206
|
+
path: entry.info.path,
|
|
207
|
+
data: entry
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
for (const entry of meta) {
|
|
211
|
+
outputs.push({
|
|
212
|
+
type: "meta",
|
|
213
|
+
absolutePath: entry.info.fullPath,
|
|
214
|
+
path: entry.info.path,
|
|
215
|
+
data: entry
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return outputs;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// src/loaders/mdx/build-mdx.ts
|
|
222
|
+
var import_mdx = require("@mdx-js/mdx");
|
|
223
|
+
|
|
224
|
+
// src/loaders/mdx/remark-include.ts
|
|
225
|
+
var import_unified = require("unified");
|
|
226
|
+
var import_unist_util_visit2 = require("unist-util-visit");
|
|
227
|
+
var path = __toESM(require("path"), 1);
|
|
228
|
+
var fs2 = __toESM(require("fs/promises"), 1);
|
|
229
|
+
|
|
230
|
+
// src/utils/fuma-matter.ts
|
|
231
|
+
var import_js_yaml = require("js-yaml");
|
|
232
|
+
var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
|
|
233
|
+
function fumaMatter(input) {
|
|
234
|
+
const output = { matter: "", data: {}, content: input };
|
|
235
|
+
const match = regex.exec(input);
|
|
236
|
+
if (!match) {
|
|
237
|
+
return output;
|
|
238
|
+
}
|
|
239
|
+
output.matter = match[0];
|
|
240
|
+
output.content = input.slice(match[0].length);
|
|
241
|
+
const loaded = (0, import_js_yaml.load)(match[1]);
|
|
242
|
+
output.data = loaded ?? {};
|
|
243
|
+
return output;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// src/loaders/mdx/remark-include.ts
|
|
247
|
+
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
248
|
+
|
|
249
|
+
// src/loaders/mdx/remark-unravel.ts
|
|
250
|
+
var import_unist_util_visit = require("unist-util-visit");
|
|
251
|
+
function remarkMarkAndUnravel() {
|
|
252
|
+
return (tree) => {
|
|
253
|
+
(0, import_unist_util_visit.visit)(tree, function(node, index, parent) {
|
|
254
|
+
let offset = -1;
|
|
255
|
+
let all = true;
|
|
256
|
+
let oneOrMore = false;
|
|
257
|
+
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
258
|
+
const children = node.children;
|
|
259
|
+
while (++offset < children.length) {
|
|
260
|
+
const child = children[offset];
|
|
261
|
+
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") {
|
|
262
|
+
oneOrMore = true;
|
|
263
|
+
} else if (child.type === "text" && child.value.trim().length === 0) {
|
|
264
|
+
} else {
|
|
265
|
+
all = false;
|
|
266
|
+
break;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
if (all && oneOrMore) {
|
|
270
|
+
offset = -1;
|
|
271
|
+
const newChildren = [];
|
|
272
|
+
while (++offset < children.length) {
|
|
273
|
+
const child = children[offset];
|
|
274
|
+
if (child.type === "mdxJsxTextElement") {
|
|
275
|
+
child.type = "mdxJsxFlowElement";
|
|
276
|
+
}
|
|
277
|
+
if (child.type === "mdxTextExpression") {
|
|
278
|
+
child.type = "mdxFlowExpression";
|
|
279
|
+
}
|
|
280
|
+
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {
|
|
281
|
+
} else {
|
|
282
|
+
newChildren.push(child);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
parent.children.splice(index, 1, ...newChildren);
|
|
286
|
+
return index;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// src/loaders/mdx/remark-include.ts
|
|
294
|
+
var ElementLikeTypes = [
|
|
295
|
+
"mdxJsxFlowElement",
|
|
296
|
+
"mdxJsxTextElement",
|
|
297
|
+
"containerDirective",
|
|
298
|
+
"textDirective",
|
|
299
|
+
"leafDirective"
|
|
300
|
+
];
|
|
301
|
+
function isElementLike(node) {
|
|
302
|
+
return ElementLikeTypes.includes(node.type);
|
|
303
|
+
}
|
|
304
|
+
function parseElementAttributes(element) {
|
|
305
|
+
if (Array.isArray(element.attributes)) {
|
|
306
|
+
const attributes = {};
|
|
307
|
+
for (const attr of element.attributes) {
|
|
308
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
309
|
+
attributes[attr.name] = attr.value;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
return attributes;
|
|
313
|
+
}
|
|
314
|
+
return element.attributes ?? {};
|
|
315
|
+
}
|
|
316
|
+
function flattenNode(node) {
|
|
317
|
+
if ("children" in node)
|
|
318
|
+
return node.children.map((child) => flattenNode(child)).join("");
|
|
319
|
+
if ("value" in node) return node.value;
|
|
320
|
+
return "";
|
|
321
|
+
}
|
|
322
|
+
function parseSpecifier(specifier) {
|
|
323
|
+
const idx = specifier.lastIndexOf("#");
|
|
324
|
+
if (idx === -1) return { file: specifier };
|
|
325
|
+
return {
|
|
326
|
+
file: specifier.slice(0, idx),
|
|
327
|
+
section: specifier.slice(idx + 1)
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
function extractSection(root, section) {
|
|
331
|
+
let nodes;
|
|
332
|
+
let capturingHeadingContent = false;
|
|
333
|
+
(0, import_unist_util_visit2.visit)(root, (node) => {
|
|
334
|
+
if (node.type === "heading") {
|
|
335
|
+
if (capturingHeadingContent) {
|
|
336
|
+
return false;
|
|
337
|
+
}
|
|
338
|
+
if (node.data?.hProperties?.id === section) {
|
|
339
|
+
capturingHeadingContent = true;
|
|
340
|
+
nodes = [node];
|
|
341
|
+
return "skip";
|
|
342
|
+
}
|
|
343
|
+
return;
|
|
344
|
+
}
|
|
345
|
+
if (capturingHeadingContent) {
|
|
346
|
+
nodes?.push(node);
|
|
347
|
+
return "skip";
|
|
348
|
+
}
|
|
349
|
+
if (isElementLike(node) && node.name === "section") {
|
|
350
|
+
const attributes = parseElementAttributes(node);
|
|
351
|
+
if (attributes.id === section) {
|
|
352
|
+
nodes = node.children;
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
if (nodes)
|
|
358
|
+
return {
|
|
359
|
+
type: "root",
|
|
360
|
+
children: nodes
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
function remarkInclude() {
|
|
364
|
+
const TagName = "include";
|
|
365
|
+
const embedContent = async (file, heading, params, data) => {
|
|
366
|
+
let content;
|
|
367
|
+
try {
|
|
368
|
+
content = (await fs2.readFile(file)).toString();
|
|
369
|
+
} catch (e) {
|
|
370
|
+
throw new Error(
|
|
371
|
+
`failed to read file ${file}
|
|
372
|
+
${e instanceof Error ? e.message : String(e)}`,
|
|
373
|
+
{ cause: e }
|
|
374
|
+
);
|
|
375
|
+
}
|
|
376
|
+
const ext = path.extname(file);
|
|
377
|
+
data._compiler?.addDependency(file);
|
|
378
|
+
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
379
|
+
const lang = params.lang ?? ext.slice(1);
|
|
380
|
+
return {
|
|
381
|
+
type: "code",
|
|
382
|
+
lang,
|
|
383
|
+
meta: params.meta,
|
|
384
|
+
value: content,
|
|
385
|
+
data: {}
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
const parser = data._getProcessor ? data._getProcessor(ext === ".mdx" ? "mdx" : "md") : this;
|
|
389
|
+
const parsed = fumaMatter(content);
|
|
390
|
+
let mdast = parser.parse({
|
|
391
|
+
path: file,
|
|
392
|
+
value: parsed.content,
|
|
393
|
+
data: { frontmatter: parsed.data }
|
|
394
|
+
});
|
|
395
|
+
const baseProcessor = (0, import_unified.unified)().use(remarkMarkAndUnravel);
|
|
396
|
+
if (heading) {
|
|
397
|
+
const extracted = extractSection(
|
|
398
|
+
await baseProcessor.use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
399
|
+
heading
|
|
400
|
+
);
|
|
401
|
+
if (!extracted)
|
|
402
|
+
throw new Error(
|
|
403
|
+
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`
|
|
404
|
+
);
|
|
405
|
+
mdast = extracted;
|
|
406
|
+
} else {
|
|
407
|
+
mdast = await baseProcessor.run(mdast);
|
|
408
|
+
}
|
|
409
|
+
await update(mdast, path.dirname(file), data);
|
|
410
|
+
return mdast;
|
|
411
|
+
};
|
|
412
|
+
async function update(tree, directory, data) {
|
|
413
|
+
const queue = [];
|
|
414
|
+
(0, import_unist_util_visit2.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
415
|
+
const node = _node;
|
|
416
|
+
if (node.name !== TagName) return;
|
|
417
|
+
const specifier = flattenNode(node);
|
|
418
|
+
if (specifier.length === 0) return "skip";
|
|
419
|
+
const attributes = parseElementAttributes(node);
|
|
420
|
+
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
421
|
+
const file = path.resolve(
|
|
422
|
+
"cwd" in attributes ? process.cwd() : directory,
|
|
423
|
+
relativePath
|
|
424
|
+
);
|
|
425
|
+
queue.push(
|
|
426
|
+
embedContent(file, section, attributes, data).then((replace) => {
|
|
427
|
+
Object.assign(
|
|
428
|
+
parent && parent.type === "paragraph" ? parent : node,
|
|
429
|
+
replace
|
|
430
|
+
);
|
|
431
|
+
})
|
|
432
|
+
);
|
|
433
|
+
return "skip";
|
|
434
|
+
});
|
|
435
|
+
await Promise.all(queue);
|
|
436
|
+
}
|
|
437
|
+
return async (tree, file) => {
|
|
438
|
+
await update(tree, path.dirname(file.path), file.data);
|
|
439
|
+
};
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
// src/loaders/mdx/remark-postprocess.ts
|
|
443
|
+
var import_unist_util_visit3 = require("unist-util-visit");
|
|
444
|
+
var import_mdast_util_to_markdown = require("mdast-util-to-markdown");
|
|
445
|
+
var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
|
|
446
|
+
var import_unist_util_remove_position = require("unist-util-remove-position");
|
|
447
|
+
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
448
|
+
function remarkPostprocess({
|
|
449
|
+
_format,
|
|
450
|
+
includeProcessedMarkdown = false,
|
|
451
|
+
includeMDAST = false,
|
|
452
|
+
valueToExport = []
|
|
453
|
+
}) {
|
|
454
|
+
let _stringifyProcessor;
|
|
455
|
+
const getStringifyProcessor = () => {
|
|
456
|
+
if (_format === "mdx") return this;
|
|
457
|
+
return _stringifyProcessor ??= this().use(import_remark_mdx.default).freeze();
|
|
458
|
+
};
|
|
459
|
+
return (tree, file) => {
|
|
460
|
+
let title;
|
|
461
|
+
const urls = [];
|
|
462
|
+
(0, import_unist_util_visit3.visit)(tree, ["heading", "link"], (node) => {
|
|
463
|
+
if (node.type === "heading" && node.depth === 1) {
|
|
464
|
+
title = flattenNode2(node);
|
|
465
|
+
}
|
|
466
|
+
if (node.type !== "link") return;
|
|
467
|
+
urls.push({
|
|
468
|
+
href: node.url
|
|
469
|
+
});
|
|
470
|
+
return "skip";
|
|
471
|
+
});
|
|
472
|
+
if (title) {
|
|
473
|
+
file.data.frontmatter ??= {};
|
|
474
|
+
if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
|
|
475
|
+
}
|
|
476
|
+
file.data.extractedReferences = urls;
|
|
477
|
+
if (includeProcessedMarkdown) {
|
|
478
|
+
const processor = getStringifyProcessor();
|
|
479
|
+
file.data._markdown = (0, import_mdast_util_to_markdown.toMarkdown)(tree, {
|
|
480
|
+
...processor.data("settings"),
|
|
481
|
+
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
482
|
+
extensions: processor.data("toMarkdownExtensions") || []
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
if (includeMDAST) {
|
|
486
|
+
const options = includeMDAST === true ? {} : includeMDAST;
|
|
487
|
+
file.data._mdast = JSON.stringify(
|
|
488
|
+
options.removePosition ? (0, import_unist_util_remove_position.removePosition)(structuredClone(tree)) : tree
|
|
489
|
+
);
|
|
490
|
+
}
|
|
491
|
+
for (const { name, value } of file.data["mdx-export"] ?? []) {
|
|
492
|
+
tree.children.unshift(getMdastExport(name, value));
|
|
493
|
+
}
|
|
494
|
+
for (const name of valueToExport) {
|
|
495
|
+
if (!(name in file.data)) continue;
|
|
496
|
+
tree.children.unshift(getMdastExport(name, file.data[name]));
|
|
497
|
+
}
|
|
498
|
+
};
|
|
499
|
+
}
|
|
500
|
+
function getMdastExport(name, value) {
|
|
501
|
+
return {
|
|
502
|
+
type: "mdxjsEsm",
|
|
503
|
+
value: "",
|
|
504
|
+
data: {
|
|
505
|
+
estree: {
|
|
506
|
+
type: "Program",
|
|
507
|
+
sourceType: "module",
|
|
508
|
+
body: [
|
|
509
|
+
{
|
|
510
|
+
type: "ExportNamedDeclaration",
|
|
511
|
+
attributes: [],
|
|
512
|
+
specifiers: [],
|
|
513
|
+
source: null,
|
|
514
|
+
declaration: {
|
|
515
|
+
type: "VariableDeclaration",
|
|
516
|
+
kind: "let",
|
|
517
|
+
declarations: [
|
|
518
|
+
{
|
|
519
|
+
type: "VariableDeclarator",
|
|
520
|
+
id: {
|
|
521
|
+
type: "Identifier",
|
|
522
|
+
name
|
|
523
|
+
},
|
|
524
|
+
init: (0, import_estree_util_value_to_estree.valueToEstree)(value)
|
|
525
|
+
}
|
|
526
|
+
]
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
]
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
function flattenNode2(node) {
|
|
535
|
+
if ("children" in node)
|
|
536
|
+
return node.children.map((child) => flattenNode2(child)).join("");
|
|
537
|
+
if ("value" in node) return node.value;
|
|
538
|
+
return "";
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
// src/loaders/mdx/build-mdx.ts
|
|
542
|
+
var cache = /* @__PURE__ */ new Map();
|
|
543
|
+
async function buildMDX(cacheKey, source, options) {
|
|
544
|
+
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
545
|
+
function getProcessor(format) {
|
|
546
|
+
const key = `${cacheKey}:${format}`;
|
|
547
|
+
let processor = cache.get(key);
|
|
548
|
+
if (!processor) {
|
|
549
|
+
processor = (0, import_mdx.createProcessor)({
|
|
550
|
+
outputFormat: "program",
|
|
551
|
+
...rest,
|
|
552
|
+
remarkPlugins: [
|
|
553
|
+
remarkInclude,
|
|
554
|
+
...rest.remarkPlugins ?? [],
|
|
555
|
+
[
|
|
556
|
+
remarkPostprocess,
|
|
557
|
+
{
|
|
558
|
+
_format: format,
|
|
559
|
+
...options.postprocess,
|
|
560
|
+
valueToExport: [
|
|
561
|
+
...options.postprocess?.valueToExport ?? [],
|
|
562
|
+
"structuredData",
|
|
563
|
+
"extractedReferences",
|
|
564
|
+
"frontmatter",
|
|
565
|
+
"lastModified",
|
|
566
|
+
"_markdown",
|
|
567
|
+
"_mdast"
|
|
568
|
+
]
|
|
569
|
+
}
|
|
570
|
+
]
|
|
571
|
+
],
|
|
572
|
+
format
|
|
573
|
+
});
|
|
574
|
+
cache.set(key, processor);
|
|
575
|
+
}
|
|
576
|
+
return processor;
|
|
577
|
+
}
|
|
578
|
+
return getProcessor(
|
|
579
|
+
options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
|
|
580
|
+
).process({
|
|
581
|
+
value: source,
|
|
582
|
+
path: filePath,
|
|
583
|
+
data: {
|
|
584
|
+
...data,
|
|
585
|
+
frontmatter,
|
|
586
|
+
_compiler,
|
|
587
|
+
_getProcessor: getProcessor
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
// src/runtime/next/async.ts
|
|
593
|
+
var import_client = require("@fumadocs/mdx-remote/client");
|
|
594
|
+
var import_node_url = require("url");
|
|
595
|
+
var import_promises2 = __toESM(require("fs/promises"), 1);
|
|
596
|
+
|
|
597
|
+
// src/config/build.ts
|
|
598
|
+
function buildConfig(config) {
|
|
599
|
+
const collections = /* @__PURE__ */ new Map();
|
|
600
|
+
let globalConfig = {};
|
|
601
|
+
for (const [k, v] of Object.entries(config)) {
|
|
602
|
+
if (!v) {
|
|
603
|
+
continue;
|
|
604
|
+
}
|
|
605
|
+
if (typeof v === "object" && "type" in v) {
|
|
606
|
+
if (v.type === "docs") {
|
|
607
|
+
collections.set(k, v);
|
|
608
|
+
continue;
|
|
609
|
+
}
|
|
610
|
+
if (v.type === "doc" || v.type === "meta") {
|
|
611
|
+
collections.set(k, v);
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
if (k === "default" && v) {
|
|
616
|
+
globalConfig = v;
|
|
617
|
+
continue;
|
|
618
|
+
}
|
|
619
|
+
throw new Error(
|
|
620
|
+
`Unknown export "${k}", you can only export collections from source configuration file.`
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
const mdxOptionsCache = /* @__PURE__ */ new Map();
|
|
624
|
+
return {
|
|
625
|
+
global: globalConfig,
|
|
626
|
+
collections,
|
|
627
|
+
async getDefaultMDXOptions(mode = "default") {
|
|
628
|
+
const cached = mdxOptionsCache.get(mode);
|
|
629
|
+
if (cached) return cached;
|
|
630
|
+
const input = this.global.mdxOptions;
|
|
631
|
+
async function uncached() {
|
|
632
|
+
const options = typeof input === "function" ? await input() : input;
|
|
633
|
+
const { getDefaultMDXOptions: getDefaultMDXOptions2 } = await Promise.resolve().then(() => (init_preset(), preset_exports));
|
|
634
|
+
if (options?.preset === "minimal") return options;
|
|
635
|
+
return getDefaultMDXOptions2({
|
|
636
|
+
...options,
|
|
637
|
+
_withoutBundler: mode === "remote"
|
|
638
|
+
});
|
|
639
|
+
}
|
|
640
|
+
const result = uncached();
|
|
641
|
+
mdxOptionsCache.set(mode, result);
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// src/runtime/next/async.ts
|
|
648
|
+
function getDocCollection(config, collection) {
|
|
649
|
+
const col = config.collections.get(collection);
|
|
650
|
+
if (col?.type === "doc" && col.mdxOptions) return col;
|
|
651
|
+
if (col?.type === "docs" && col.docs.mdxOptions) return col.docs;
|
|
652
|
+
}
|
|
653
|
+
async function getOptions(config, collection) {
|
|
654
|
+
return collection?.mdxOptions ?? await config.getDefaultMDXOptions("remote");
|
|
655
|
+
}
|
|
656
|
+
var _runtimeAsync = {
|
|
657
|
+
doc(files, collectionName, config) {
|
|
658
|
+
const collection = getDocCollection(config, collectionName);
|
|
659
|
+
const initMdxOptions = getOptions(config, collection);
|
|
660
|
+
return files.map(({ info, data, lastModified }) => {
|
|
661
|
+
let cachedResult;
|
|
662
|
+
async function compileAndLoad() {
|
|
663
|
+
if (cachedResult) return cachedResult;
|
|
664
|
+
const mdxOptions = await initMdxOptions;
|
|
665
|
+
const raw = (await import_promises2.default.readFile(info.fullPath)).toString();
|
|
666
|
+
const { content } = fumaMatter(raw);
|
|
667
|
+
const compiled = await buildMDX(collectionName, content, {
|
|
668
|
+
...mdxOptions,
|
|
669
|
+
development: false,
|
|
670
|
+
frontmatter: data,
|
|
671
|
+
postprocess: collection?.postprocess,
|
|
672
|
+
data: {
|
|
673
|
+
lastModified
|
|
674
|
+
},
|
|
675
|
+
filePath: info.fullPath
|
|
676
|
+
});
|
|
677
|
+
const result = await (0, import_client.executeMdx)(String(compiled.value), {
|
|
678
|
+
baseUrl: (0, import_node_url.pathToFileURL)(info.fullPath)
|
|
679
|
+
});
|
|
680
|
+
return cachedResult = result;
|
|
681
|
+
}
|
|
682
|
+
return {
|
|
683
|
+
...data,
|
|
684
|
+
...createDocMethods(info, () => compileAndLoad()),
|
|
685
|
+
async load() {
|
|
686
|
+
const out = await compileAndLoad();
|
|
687
|
+
return {
|
|
688
|
+
_exports: out,
|
|
689
|
+
body: out.default,
|
|
690
|
+
lastModified,
|
|
691
|
+
toc: out.toc,
|
|
692
|
+
extractedReferences: out.extractedReferences,
|
|
693
|
+
structuredData: out.structuredData
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
});
|
|
698
|
+
},
|
|
699
|
+
docs(docs, metas, collection, config) {
|
|
700
|
+
const parsedDocs = this.doc(docs, collection, config);
|
|
701
|
+
const parsedMetas = _runtime.meta(metas);
|
|
702
|
+
return {
|
|
703
|
+
docs: parsedDocs,
|
|
704
|
+
meta: parsedMetas,
|
|
705
|
+
toFumadocsSource() {
|
|
706
|
+
return createMDXSource(parsedDocs, parsedMetas);
|
|
707
|
+
}
|
|
708
|
+
};
|
|
709
|
+
}
|
|
710
|
+
};
|
|
711
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
712
|
+
0 && (module.exports = {
|
|
713
|
+
_runtimeAsync,
|
|
714
|
+
buildConfig
|
|
715
|
+
});
|