fumadocs-mdx 11.8.1 → 11.8.2

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.
Files changed (34) hide show
  1. package/dist/{build-mdx-DMe0r3s_.d.cts → build-mdx-DnC1jKvn.d.cts} +6 -4
  2. package/dist/{build-mdx-DMe0r3s_.d.ts → build-mdx-DnC1jKvn.d.ts} +6 -4
  3. package/dist/{chunk-BCOXAJMC.js → chunk-BWRDVK5L.js} +1 -1
  4. package/dist/{chunk-7JFPDRW7.js → chunk-QQWCBFFE.js} +2 -4
  5. package/dist/{chunk-S73DGUHI.js → chunk-QVZ7JH4H.js} +1 -1
  6. package/dist/{chunk-DJNS22RO.js → chunk-SMSNZ6N5.js} +37 -23
  7. package/dist/chunk-SVTXMVLQ.js +139 -0
  8. package/dist/config/index.cjs +118 -84
  9. package/dist/config/index.d.cts +5 -1
  10. package/dist/config/index.d.ts +5 -1
  11. package/dist/config/index.js +2 -2
  12. package/dist/config/zod-3.cjs +118 -84
  13. package/dist/config/zod-3.d.cts +1 -1
  14. package/dist/config/zod-3.d.ts +1 -1
  15. package/dist/config/zod-3.js +2 -2
  16. package/dist/index.d.cts +2 -2
  17. package/dist/index.d.ts +2 -2
  18. package/dist/loader-mdx.cjs +127 -102
  19. package/dist/loader-mdx.js +8 -8
  20. package/dist/{mdx-options-ILHLYYTL.js → mdx-options-T73E4LQB.js} +1 -1
  21. package/dist/next/index.cjs +41 -34
  22. package/dist/next/index.js +2 -2
  23. package/dist/runtime/async.cjs +121 -96
  24. package/dist/runtime/async.d.cts +2 -2
  25. package/dist/runtime/async.d.ts +2 -2
  26. package/dist/runtime/async.js +3 -3
  27. package/dist/runtime/vite.d.cts +1 -1
  28. package/dist/runtime/vite.d.ts +1 -1
  29. package/dist/{types-DvnkeVI3.d.cts → types-BmVgoqsr.d.cts} +1 -1
  30. package/dist/{types-zBRxlyaM.d.ts → types-WSHJKA8L.d.ts} +1 -1
  31. package/dist/vite/index.cjs +123 -98
  32. package/dist/vite/index.js +3 -3
  33. package/package.json +9 -7
  34. package/dist/chunk-IGXZS2W6.js +0 -119
@@ -94,16 +94,42 @@ function defineConfig(config = {}) {
94
94
  // src/utils/mdx-options.ts
95
95
  var plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
96
96
 
97
- // src/mdx-plugins/remark-exports.ts
97
+ // src/mdx-plugins/remark-postprocess.ts
98
+ var import_unist_util_visit = require("unist-util-visit");
98
99
  var import_estree_util_value_to_estree = require("estree-util-value-to-estree");
99
- function remarkMdxExport({ values }) {
100
- return (tree, vfile) => {
101
- for (const name of values) {
102
- if (!(name in vfile.data)) continue;
103
- tree.children.unshift(getMdastExport(name, vfile.data[name]));
100
+ function remarkPostprocess({
101
+ injectExports
102
+ }) {
103
+ return (tree, file) => {
104
+ let title;
105
+ const urls = [];
106
+ (0, import_unist_util_visit.visit)(tree, ["heading", "link"], (node) => {
107
+ if (node.type === "heading" && node.depth === 1) {
108
+ title = flattenNode(node);
109
+ }
110
+ if (node.type !== "link") return;
111
+ urls.push({
112
+ href: node.url
113
+ });
114
+ return "skip";
115
+ });
116
+ if (title) {
117
+ file.data.frontmatter ??= {};
118
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
119
+ }
120
+ file.data.extractedReferences = urls;
121
+ for (const name of injectExports) {
122
+ if (!(name in file.data)) continue;
123
+ tree.children.unshift(getMdastExport(name, file.data[name]));
104
124
  }
105
125
  };
106
126
  }
127
+ function flattenNode(node) {
128
+ if ("children" in node)
129
+ return node.children.map((child) => flattenNode(child)).join("");
130
+ if ("value" in node) return node.value;
131
+ return "";
132
+ }
107
133
  function getMdastExport(name, value) {
108
134
  return {
109
135
  type: "mdxjsEsm",
@@ -115,6 +141,7 @@ function getMdastExport(name, value) {
115
141
  body: [
116
142
  {
117
143
  type: "ExportNamedDeclaration",
144
+ attributes: [],
118
145
  specifiers: [],
119
146
  source: null,
120
147
  declaration: {
@@ -138,21 +165,6 @@ function getMdastExport(name, value) {
138
165
  };
139
166
  }
140
167
 
141
- // src/mdx-plugins/remark-extract.ts
142
- var import_unist_util_visit = require("unist-util-visit");
143
- function remarkExtract() {
144
- return (tree, file) => {
145
- const urls = [];
146
- (0, import_unist_util_visit.visit)(tree, "link", (node) => {
147
- urls.push({
148
- href: node.url
149
- });
150
- return "skip";
151
- });
152
- file.data.extractedReferences = urls;
153
- };
154
- }
155
-
156
168
  // src/utils/mdx-options.ts
157
169
  function pluginOption(def, options = []) {
158
170
  const list = def(Array.isArray(options) ? options : []).filter(
@@ -204,12 +216,14 @@ function getDefaultMDXOptions({
204
216
  ],
205
217
  "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
206
218
  ...v,
207
- remarkExtract,
208
219
  remarkStructureOptions !== false && [
209
220
  plugins.remarkStructure,
210
221
  remarkStructureOptions
211
222
  ],
212
- [remarkMdxExport, { values: mdxExports }]
223
+ [
224
+ remarkPostprocess,
225
+ { injectExports: mdxExports }
226
+ ]
213
227
  ],
214
228
  mdxOptions.remarkPlugins
215
229
  );
@@ -230,6 +244,7 @@ function getDefaultMDXOptions({
230
244
  }
231
245
 
232
246
  // src/mdx-plugins/remark-include.ts
247
+ var import_unified = require("unified");
233
248
  var import_unist_util_visit2 = require("unist-util-visit");
234
249
  var path = __toESM(require("path"), 1);
235
250
  var fs = __toESM(require("fs/promises"), 1);
@@ -251,9 +266,13 @@ function fumaMatter(input) {
251
266
  }
252
267
 
253
268
  // src/mdx-plugins/remark-include.ts
254
- function flattenNode(node) {
269
+ var import_remark_parse = __toESM(require("remark-parse"), 1);
270
+ var import_remark_mdx = __toESM(require("remark-mdx"), 1);
271
+ var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
272
+ var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
273
+ function flattenNode2(node) {
255
274
  if ("children" in node)
256
- return node.children.map((child) => flattenNode(child)).join("");
275
+ return node.children.map((child) => flattenNode2(child)).join("");
257
276
  if ("value" in node) return node.value;
258
277
  return "";
259
278
  }
@@ -266,86 +285,96 @@ function parseSpecifier(specifier) {
266
285
  };
267
286
  }
268
287
  function extractSection(root, section) {
288
+ let nodes;
269
289
  for (const node of root.children) {
270
290
  if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
271
291
  (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
272
292
  )) {
273
- return {
274
- type: "root",
275
- children: node.children
276
- };
293
+ nodes = node.children;
294
+ break;
295
+ }
296
+ if (node.type === "heading" && node.data?.hProperties?.id === section) {
297
+ nodes = [node];
298
+ continue;
277
299
  }
300
+ if (!nodes) continue;
301
+ if (node.type === "heading") break;
302
+ nodes.push(node);
278
303
  }
304
+ if (nodes)
305
+ return {
306
+ type: "root",
307
+ children: nodes
308
+ };
279
309
  }
280
310
  function remarkInclude() {
281
311
  const TagName = "include";
312
+ async function embedContent(file, heading, params, data) {
313
+ let content;
314
+ try {
315
+ content = (await fs.readFile(file)).toString();
316
+ } catch (e) {
317
+ throw new Error(
318
+ `failed to read file ${file}
319
+ ${e instanceof Error ? e.message : String(e)}`,
320
+ { cause: e }
321
+ );
322
+ }
323
+ const ext = path.extname(file);
324
+ data._compiler?.addDependency(file);
325
+ if (params.lang || ext !== ".md" && ext !== ".mdx") {
326
+ const lang = params.lang ?? ext.slice(1);
327
+ return {
328
+ type: "code",
329
+ lang,
330
+ meta: params.meta,
331
+ value: content,
332
+ data: {}
333
+ };
334
+ }
335
+ const processor = (data._getProcessor ?? getDefaultProcessor)(
336
+ ext === ".mdx" ? "mdx" : "md"
337
+ );
338
+ let parsed = await baseProcessor.run(
339
+ processor.parse(fumaMatter(content).content)
340
+ );
341
+ if (heading) {
342
+ const extracted = extractSection(parsed, heading);
343
+ if (!extracted)
344
+ throw new Error(
345
+ `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
346
+ );
347
+ parsed = extracted;
348
+ }
349
+ await update(parsed, path.dirname(file), data);
350
+ return parsed;
351
+ }
282
352
  async function update(tree, directory, data) {
283
353
  const queue = [];
284
354
  (0, import_unist_util_visit2.visit)(
285
355
  tree,
286
356
  ["mdxJsxFlowElement", "mdxJsxTextElement"],
287
- (node, _, parent) => {
288
- let specifier;
357
+ (_node, _, parent) => {
358
+ const node = _node;
359
+ if (node.name !== TagName) return;
289
360
  const params = {};
290
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
291
- const value = flattenNode(node);
292
- if (value.length > 0) {
293
- for (const attr of node.attributes) {
294
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
295
- params[attr.name] = attr.value;
296
- }
297
- }
298
- specifier = value;
361
+ const specifier = flattenNode2(node);
362
+ if (specifier.length === 0) return "skip";
363
+ for (const attr of node.attributes) {
364
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
365
+ params[attr.name] = attr.value;
299
366
  }
300
367
  }
301
- if (!specifier) return;
302
- const { file, section } = parseSpecifier(specifier);
303
- const targetPath = path.resolve(
368
+ const { file: relativePath, section } = parseSpecifier(specifier);
369
+ const file = path.resolve(
304
370
  "cwd" in params ? process.cwd() : directory,
305
- file
371
+ relativePath
306
372
  );
307
- const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
308
373
  queue.push(
309
- fs.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
310
- data._compiler?.addDependency(targetPath);
311
- if (asCode) {
312
- const lang = params.lang ?? path.extname(file).slice(1);
313
- Object.assign(node, {
314
- type: "code",
315
- lang,
316
- meta: params.meta,
317
- value: content,
318
- data: {}
319
- });
320
- return;
321
- }
322
- const processor = data._processor ? data._processor.getProcessor(
323
- targetPath.endsWith(".md") ? "md" : "mdx"
324
- ) : this;
325
- let parsed = processor.parse(fumaMatter(content).content);
326
- if (section) {
327
- const extracted = extractSection(parsed, section);
328
- if (!extracted)
329
- throw new Error(
330
- `Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
331
- );
332
- parsed = extracted;
333
- }
334
- await update.call(
335
- processor,
336
- parsed,
337
- path.dirname(targetPath),
338
- data
339
- );
374
+ embedContent(file, section, params, data).then((replace) => {
340
375
  Object.assign(
341
376
  parent && parent.type === "paragraph" ? parent : node,
342
- parsed
343
- );
344
- }).catch((e) => {
345
- throw new Error(
346
- `failed to read file ${targetPath}
347
- ${e instanceof Error ? e.message : String(e)}`,
348
- { cause: e }
377
+ replace
349
378
  );
350
379
  })
351
380
  );
@@ -355,9 +384,14 @@ ${e instanceof Error ? e.message : String(e)}`,
355
384
  await Promise.all(queue);
356
385
  }
357
386
  return async (tree, file) => {
358
- await update.call(this, tree, path.dirname(file.path), file.data);
387
+ await update(tree, path.dirname(file.path), file.data);
359
388
  };
360
389
  }
390
+ function getDefaultProcessor(format) {
391
+ const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
392
+ if (format === "md") return mdProcessor;
393
+ return mdProcessor.use(import_remark_mdx.default);
394
+ }
361
395
 
362
396
  // src/config/zod-3.ts
363
397
  var metaSchema2 = import_v3.z.object({
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod/v3';
2
2
  export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.cjs';
3
- export { remarkInclude } from './index.cjs';
3
+ export { Params, remarkInclude } from './index.cjs';
4
4
  import '@standard-schema/spec';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
@@ -1,6 +1,6 @@
1
1
  import { z } from 'zod/v3';
2
2
  export { A as AnyCollection, B as BaseCollection, C as CollectionSchema, D as DefaultMDXOptions, a as DocCollection, b as DocsCollection, G as GlobalConfig, M as MetaCollection, d as defineCollections, e as defineConfig, c as defineDocs, g as getDefaultMDXOptions } from '../define-DnJzAZrj.js';
3
- export { remarkInclude } from './index.js';
3
+ export { Params, remarkInclude } from './index.js';
4
4
  import '@standard-schema/spec';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
@@ -5,10 +5,10 @@ import {
5
5
  } from "../chunk-GBMFGEC7.js";
6
6
  import {
7
7
  getDefaultMDXOptions
8
- } from "../chunk-DJNS22RO.js";
8
+ } from "../chunk-SMSNZ6N5.js";
9
9
  import {
10
10
  remarkInclude
11
- } from "../chunk-IGXZS2W6.js";
11
+ } from "../chunk-SVTXMVLQ.js";
12
12
  import "../chunk-VWJKRQZR.js";
13
13
 
14
14
  // src/config/zod-3.ts
package/dist/index.d.cts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-DvnkeVI3.cjs';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-BmVgoqsr.cjs';
3
3
  import '@standard-schema/spec';
4
4
  import './define-DnJzAZrj.cjs';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import './build-mdx-DMe0r3s_.cjs';
9
+ import './build-mdx-DnC1jKvn.cjs';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';
package/dist/index.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { R as Runtime, B as BaseCollectionEntry } from './types-zBRxlyaM.js';
2
+ import { R as Runtime, B as BaseCollectionEntry } from './types-WSHJKA8L.js';
3
3
  import '@standard-schema/spec';
4
4
  import './define-DnJzAZrj.js';
5
5
  import 'fumadocs-core/mdx-plugins';
6
6
  import '@mdx-js/mdx';
7
7
  import 'unified';
8
8
  import 'zod';
9
- import './build-mdx-DMe0r3s_.js';
9
+ import './build-mdx-DnC1jKvn.js';
10
10
  import 'fumadocs-core/server';
11
11
  import 'react';
12
12
  import 'mdx/types';