fumadocs-mdx 12.0.0 → 12.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 +102 -84
- package/dist/bin.js +1 -1
- package/dist/bun/index.cjs +156 -130
- package/dist/bun/index.js +8 -8
- package/dist/chunk-ADR6R7HM.js +29 -0
- package/dist/{chunk-3M4SHY6K.js → chunk-FSZMKRVH.js} +1 -1
- package/dist/{chunk-POXTQZ4D.js → chunk-LGYVNESJ.js} +2 -6
- package/dist/chunk-LMG6UWCL.js +167 -0
- package/dist/{chunk-SWNOXPYJ.js → chunk-QAUWMR5D.js} +6 -6
- package/dist/{chunk-KGUBBRL6.js → chunk-SP7CHRTS.js} +9 -37
- package/dist/{chunk-YC25YEBF.js → chunk-U4MQ44TS.js} +1 -1
- package/dist/chunk-XMFLD5J6.js +30 -0
- package/dist/{chunk-TLD6JMT6.js → chunk-ZX7TM4AR.js} +4 -2
- package/dist/config/index.cjs +84 -56
- package/dist/config/index.js +2 -2
- package/dist/load-UUXLUBHL.js +9 -0
- package/dist/loader-mdx.cjs +217 -174
- package/dist/loader-mdx.js +7 -7
- package/dist/next/index.cjs +128 -108
- package/dist/next/index.js +39 -53
- package/dist/node/loader.cjs +152 -109
- package/dist/node/loader.js +6 -7
- package/dist/postinstall-SCSXM4IM.js +10 -0
- package/dist/{preset-WFEORCAB.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +117 -65
- package/dist/runtime/next/async.d.cts +1 -1
- package/dist/runtime/next/async.d.ts +1 -1
- package/dist/runtime/next/async.js +15 -8
- package/dist/runtime/next/index.d.cts +2 -2
- package/dist/runtime/next/index.d.ts +2 -2
- package/dist/{types-DLIAvrgC.d.ts → types-CFlQxTN8.d.ts} +4 -5
- package/dist/{types-Dl8HLbm5.d.cts → types-DkGjw-Uo.d.cts} +4 -5
- package/dist/vite/index.cjs +177 -145
- package/dist/vite/index.d.cts +1 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +14 -19
- package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
- package/package.json +15 -11
- package/dist/chunk-KTDVTBMH.js +0 -139
- package/dist/postinstall-U7VROOY7.js +0 -9
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
remarkInclude
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LMG6UWCL.js";
|
|
4
4
|
|
|
5
|
-
// src/mdx/build-mdx.ts
|
|
5
|
+
// src/loaders/mdx/build-mdx.ts
|
|
6
6
|
import { createProcessor } from "@mdx-js/mdx";
|
|
7
7
|
|
|
8
|
-
// src/mdx/remark-postprocess.ts
|
|
8
|
+
// src/loaders/mdx/remark-postprocess.ts
|
|
9
9
|
import { visit } from "unist-util-visit";
|
|
10
10
|
import { toMarkdown } from "mdast-util-to-markdown";
|
|
11
11
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
@@ -34,7 +34,7 @@ function remarkPostprocess({
|
|
|
34
34
|
if (includeProcessedMarkdown) {
|
|
35
35
|
file.data._markdown = toMarkdown(tree, {
|
|
36
36
|
...this.data("settings"),
|
|
37
|
-
//
|
|
37
|
+
// from https://github.com/remarkjs/remark/blob/main/packages/remark-stringify/lib/index.js
|
|
38
38
|
extensions: this.data("toMarkdownExtensions") || []
|
|
39
39
|
});
|
|
40
40
|
}
|
|
@@ -88,7 +88,7 @@ function flattenNode(node) {
|
|
|
88
88
|
return "";
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
// src/mdx/build-mdx.ts
|
|
91
|
+
// src/loaders/mdx/build-mdx.ts
|
|
92
92
|
var cache = /* @__PURE__ */ new Map();
|
|
93
93
|
async function buildMDX(cacheKey, source, options) {
|
|
94
94
|
const { filePath, frontmatter, data, _compiler, ...rest } = options;
|
|
@@ -124,7 +124,7 @@ async function buildMDX(cacheKey, source, options) {
|
|
|
124
124
|
return processor;
|
|
125
125
|
}
|
|
126
126
|
return getProcessor(
|
|
127
|
-
options.format ?? filePath.endsWith(".mdx") ? "mdx" : "md"
|
|
127
|
+
options.format ?? (filePath.endsWith(".mdx") ? "mdx" : "md")
|
|
128
128
|
).process({
|
|
129
129
|
value: source,
|
|
130
130
|
path: filePath,
|
|
@@ -2,27 +2,14 @@ import {
|
|
|
2
2
|
getGitTimestamp,
|
|
3
3
|
validate
|
|
4
4
|
} from "./chunk-IQAEAI4P.js";
|
|
5
|
-
import {
|
|
6
|
-
getConfigHash,
|
|
7
|
-
loadConfig
|
|
8
|
-
} from "./chunk-POXTQZ4D.js";
|
|
9
5
|
import {
|
|
10
6
|
buildMDX
|
|
11
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-QAUWMR5D.js";
|
|
12
8
|
import {
|
|
13
9
|
fumaMatter
|
|
14
10
|
} from "./chunk-VWJKRQZR.js";
|
|
15
11
|
|
|
16
|
-
// src/
|
|
17
|
-
function countLines(s) {
|
|
18
|
-
let num = 0;
|
|
19
|
-
for (const c of s) {
|
|
20
|
-
if (c === "\n") num++;
|
|
21
|
-
}
|
|
22
|
-
return num;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// src/loaders/mdx.ts
|
|
12
|
+
// src/loaders/mdx/index.ts
|
|
26
13
|
import { z } from "zod";
|
|
27
14
|
import fs from "fs/promises";
|
|
28
15
|
import path from "path";
|
|
@@ -121,29 +108,14 @@ function createMdxLoader(configLoader) {
|
|
|
121
108
|
function generateCacheHash(input) {
|
|
122
109
|
return createHash("md5").update(input).digest("hex");
|
|
123
110
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function dynamicConfig(configPath, outDir) {
|
|
134
|
-
return {
|
|
135
|
-
async getConfig(hash) {
|
|
136
|
-
return loadConfig(
|
|
137
|
-
configPath,
|
|
138
|
-
outDir,
|
|
139
|
-
hash ?? await getConfigHash(configPath)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
111
|
+
function countLines(s) {
|
|
112
|
+
let num = 0;
|
|
113
|
+
for (const c of s) {
|
|
114
|
+
if (c === "\n") num++;
|
|
115
|
+
}
|
|
116
|
+
return num;
|
|
143
117
|
}
|
|
144
118
|
|
|
145
119
|
export {
|
|
146
|
-
createMdxLoader
|
|
147
|
-
resolvedConfig,
|
|
148
|
-
dynamicConfig
|
|
120
|
+
createMdxLoader
|
|
149
121
|
};
|
|
@@ -34,7 +34,7 @@ function buildConfig(config) {
|
|
|
34
34
|
const input = this.global.mdxOptions;
|
|
35
35
|
async function uncached() {
|
|
36
36
|
const options = typeof input === "function" ? await input() : input;
|
|
37
|
-
const { getDefaultMDXOptions } = await import("./preset-
|
|
37
|
+
const { getDefaultMDXOptions } = await import("./preset-ZMP6U62C.js");
|
|
38
38
|
if (options?.preset === "minimal") return options;
|
|
39
39
|
return getDefaultMDXOptions({
|
|
40
40
|
...options,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/loaders/config/index.ts
|
|
2
|
+
import path from "path";
|
|
3
|
+
function findConfigFile() {
|
|
4
|
+
return path.resolve("source.config.ts");
|
|
5
|
+
}
|
|
6
|
+
function resolvedConfig(loaded) {
|
|
7
|
+
return {
|
|
8
|
+
getConfig() {
|
|
9
|
+
return loaded;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function dynamicConfig(configPath, outDir) {
|
|
14
|
+
return {
|
|
15
|
+
async getConfig(hash) {
|
|
16
|
+
const { loadConfig, getConfigHash } = await import("./load-UUXLUBHL.js");
|
|
17
|
+
return loadConfig(
|
|
18
|
+
configPath,
|
|
19
|
+
outDir,
|
|
20
|
+
hash ?? await getConfigHash(configPath)
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export {
|
|
27
|
+
findConfigFile,
|
|
28
|
+
resolvedConfig,
|
|
29
|
+
dynamicConfig
|
|
30
|
+
};
|
|
@@ -4,9 +4,11 @@ import {
|
|
|
4
4
|
toImportPath
|
|
5
5
|
} from "./chunk-6Y5JDZHD.js";
|
|
6
6
|
import {
|
|
7
|
-
findConfigFile,
|
|
8
7
|
loadConfig
|
|
9
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-LGYVNESJ.js";
|
|
9
|
+
import {
|
|
10
|
+
findConfigFile
|
|
11
|
+
} from "./chunk-XMFLD5J6.js";
|
|
10
12
|
|
|
11
13
|
// src/vite/postinstall.ts
|
|
12
14
|
import fs from "fs/promises";
|
package/dist/config/index.cjs
CHANGED
|
@@ -86,7 +86,7 @@ function defineConfig(config = {}) {
|
|
|
86
86
|
return config;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
// src/mdx/preset.ts
|
|
89
|
+
// src/loaders/mdx/preset.ts
|
|
90
90
|
var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
|
|
91
91
|
function pluginOption(def, options = []) {
|
|
92
92
|
const list = def(Array.isArray(options) ? options : []).filter(
|
|
@@ -163,7 +163,7 @@ function getDefaultMDXOptions({
|
|
|
163
163
|
};
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
// src/mdx/remark-include.ts
|
|
166
|
+
// src/loaders/mdx/remark-include.ts
|
|
167
167
|
var import_unified = require("unified");
|
|
168
168
|
var import_unist_util_visit = require("unist-util-visit");
|
|
169
169
|
var path = __toESM(require("path"), 1);
|
|
@@ -185,11 +185,32 @@ function fumaMatter(input) {
|
|
|
185
185
|
return output;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
// src/mdx/remark-include.ts
|
|
188
|
+
// src/loaders/mdx/remark-include.ts
|
|
189
189
|
var import_remark_parse = __toESM(require("remark-parse"), 1);
|
|
190
190
|
var import_remark_mdx = __toESM(require("remark-mdx"), 1);
|
|
191
191
|
var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
|
|
192
|
-
var
|
|
192
|
+
var ElementLikeTypes = [
|
|
193
|
+
"mdxJsxFlowElement",
|
|
194
|
+
"mdxJsxTextElement",
|
|
195
|
+
"containerDirective",
|
|
196
|
+
"textDirective",
|
|
197
|
+
"leafDirective"
|
|
198
|
+
];
|
|
199
|
+
function isElementLike(node) {
|
|
200
|
+
return ElementLikeTypes.includes(node.type);
|
|
201
|
+
}
|
|
202
|
+
function parseElementAttributes(element) {
|
|
203
|
+
if (Array.isArray(element.attributes)) {
|
|
204
|
+
const attributes = {};
|
|
205
|
+
for (const attr of element.attributes) {
|
|
206
|
+
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
207
|
+
attributes[attr.name] = attr.value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return attributes;
|
|
211
|
+
}
|
|
212
|
+
return element.attributes ?? {};
|
|
213
|
+
}
|
|
193
214
|
function flattenNode(node) {
|
|
194
215
|
if ("children" in node)
|
|
195
216
|
return node.children.map((child) => flattenNode(child)).join("");
|
|
@@ -206,21 +227,31 @@ function parseSpecifier(specifier) {
|
|
|
206
227
|
}
|
|
207
228
|
function extractSection(root, section) {
|
|
208
229
|
let nodes;
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
230
|
+
let capturingHeadingContent = false;
|
|
231
|
+
(0, import_unist_util_visit.visit)(root, (node) => {
|
|
232
|
+
if (node.type === "heading") {
|
|
233
|
+
if (capturingHeadingContent) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (node.data?.hProperties?.id === section) {
|
|
237
|
+
capturingHeadingContent = true;
|
|
238
|
+
nodes = [node];
|
|
239
|
+
return "skip";
|
|
240
|
+
}
|
|
241
|
+
return;
|
|
215
242
|
}
|
|
216
|
-
if (
|
|
217
|
-
nodes
|
|
218
|
-
|
|
243
|
+
if (capturingHeadingContent) {
|
|
244
|
+
nodes?.push(node);
|
|
245
|
+
return "skip";
|
|
219
246
|
}
|
|
220
|
-
if (
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
247
|
+
if (isElementLike(node) && node.name === "section") {
|
|
248
|
+
const attributes = parseElementAttributes(node);
|
|
249
|
+
if (attributes.id === section) {
|
|
250
|
+
nodes = node.children;
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
224
255
|
if (nodes)
|
|
225
256
|
return {
|
|
226
257
|
type: "root",
|
|
@@ -252,55 +283,52 @@ ${e instanceof Error ? e.message : String(e)}`,
|
|
|
252
283
|
data: {}
|
|
253
284
|
};
|
|
254
285
|
}
|
|
255
|
-
const
|
|
286
|
+
const parser = (data._getProcessor ?? getDefaultProcessor)(
|
|
256
287
|
ext === ".mdx" ? "mdx" : "md"
|
|
257
288
|
);
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
289
|
+
const parsed = fumaMatter(content);
|
|
290
|
+
let mdast = parser.parse({
|
|
291
|
+
path: file,
|
|
292
|
+
value: parsed.content,
|
|
293
|
+
data: { frontmatter: parsed.data }
|
|
294
|
+
});
|
|
261
295
|
if (heading) {
|
|
262
|
-
const extracted = extractSection(
|
|
296
|
+
const extracted = extractSection(
|
|
297
|
+
await (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading).run(mdast),
|
|
298
|
+
heading
|
|
299
|
+
);
|
|
263
300
|
if (!extracted)
|
|
264
301
|
throw new Error(
|
|
265
|
-
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
|
|
302
|
+
`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.`
|
|
266
303
|
);
|
|
267
|
-
|
|
304
|
+
mdast = extracted;
|
|
268
305
|
}
|
|
269
|
-
await update(
|
|
270
|
-
return
|
|
306
|
+
await update(mdast, path.dirname(file), data);
|
|
307
|
+
return mdast;
|
|
271
308
|
}
|
|
272
309
|
async function update(tree, directory, data) {
|
|
273
310
|
const queue = [];
|
|
274
|
-
(0, import_unist_util_visit.visit)(
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
Object.assign(
|
|
296
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
297
|
-
replace
|
|
298
|
-
);
|
|
299
|
-
})
|
|
300
|
-
);
|
|
301
|
-
return "skip";
|
|
302
|
-
}
|
|
303
|
-
);
|
|
311
|
+
(0, import_unist_util_visit.visit)(tree, ElementLikeTypes, (_node, _, parent) => {
|
|
312
|
+
const node = _node;
|
|
313
|
+
if (node.name !== TagName) return;
|
|
314
|
+
const specifier = flattenNode(node);
|
|
315
|
+
if (specifier.length === 0) return "skip";
|
|
316
|
+
const attributes = parseElementAttributes(node);
|
|
317
|
+
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
318
|
+
const file = path.resolve(
|
|
319
|
+
"cwd" in attributes ? process.cwd() : directory,
|
|
320
|
+
relativePath
|
|
321
|
+
);
|
|
322
|
+
queue.push(
|
|
323
|
+
embedContent(file, section, attributes, data).then((replace) => {
|
|
324
|
+
Object.assign(
|
|
325
|
+
parent && parent.type === "paragraph" ? parent : node,
|
|
326
|
+
replace
|
|
327
|
+
);
|
|
328
|
+
})
|
|
329
|
+
);
|
|
330
|
+
return "skip";
|
|
331
|
+
});
|
|
304
332
|
await Promise.all(queue);
|
|
305
333
|
}
|
|
306
334
|
return async (tree, file) => {
|
package/dist/config/index.js
CHANGED