fumadocs-mdx 11.8.1 → 11.8.3

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 (36) 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 +6 -2
  10. package/dist/config/index.d.ts +6 -2
  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 +2 -2
  14. package/dist/config/zod-3.d.ts +2 -2
  15. package/dist/config/zod-3.js +2 -2
  16. package/dist/{define-DnJzAZrj.d.ts → define-DAZmbu3U.d.cts} +1 -1
  17. package/dist/{define-DnJzAZrj.d.cts → define-DAZmbu3U.d.ts} +1 -1
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/loader-mdx.cjs +127 -102
  21. package/dist/loader-mdx.js +8 -8
  22. package/dist/{mdx-options-ILHLYYTL.js → mdx-options-T73E4LQB.js} +1 -1
  23. package/dist/next/index.cjs +43 -38
  24. package/dist/next/index.js +4 -6
  25. package/dist/runtime/async.cjs +121 -96
  26. package/dist/runtime/async.d.cts +3 -3
  27. package/dist/runtime/async.d.ts +3 -3
  28. package/dist/runtime/async.js +3 -3
  29. package/dist/runtime/vite.d.cts +2 -2
  30. package/dist/runtime/vite.d.ts +2 -2
  31. package/dist/{types-DvnkeVI3.d.cts → types-B2kQsHs7.d.cts} +2 -2
  32. package/dist/{types-zBRxlyaM.d.ts → types-CkmezNbX.d.ts} +2 -2
  33. package/dist/vite/index.cjs +136 -98
  34. package/dist/vite/index.js +18 -3
  35. package/package.json +10 -8
  36. package/dist/chunk-IGXZS2W6.js +0 -119
@@ -30,15 +30,40 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // src/mdx-plugins/remark-exports.ts
34
- function remarkMdxExport({ values }) {
35
- return (tree, vfile) => {
36
- for (const name of values) {
37
- if (!(name in vfile.data)) continue;
38
- tree.children.unshift(getMdastExport(name, vfile.data[name]));
33
+ // src/mdx-plugins/remark-postprocess.ts
34
+ function remarkPostprocess({
35
+ injectExports
36
+ }) {
37
+ return (tree, file) => {
38
+ let title;
39
+ const urls = [];
40
+ (0, import_unist_util_visit2.visit)(tree, ["heading", "link"], (node) => {
41
+ if (node.type === "heading" && node.depth === 1) {
42
+ title = flattenNode2(node);
43
+ }
44
+ if (node.type !== "link") return;
45
+ urls.push({
46
+ href: node.url
47
+ });
48
+ return "skip";
49
+ });
50
+ if (title) {
51
+ file.data.frontmatter ??= {};
52
+ if (!file.data.frontmatter.title) file.data.frontmatter.title = title;
53
+ }
54
+ file.data.extractedReferences = urls;
55
+ for (const name of injectExports) {
56
+ if (!(name in file.data)) continue;
57
+ tree.children.unshift(getMdastExport(name, file.data[name]));
39
58
  }
40
59
  };
41
60
  }
61
+ function flattenNode2(node) {
62
+ if ("children" in node)
63
+ return node.children.map((child) => flattenNode2(child)).join("");
64
+ if ("value" in node) return node.value;
65
+ return "";
66
+ }
42
67
  function getMdastExport(name, value) {
43
68
  return {
44
69
  type: "mdxjsEsm",
@@ -50,6 +75,7 @@ function getMdastExport(name, value) {
50
75
  body: [
51
76
  {
52
77
  type: "ExportNamedDeclaration",
78
+ attributes: [],
53
79
  specifiers: [],
54
80
  source: null,
55
81
  declaration: {
@@ -72,32 +98,12 @@ function getMdastExport(name, value) {
72
98
  }
73
99
  };
74
100
  }
75
- var import_estree_util_value_to_estree;
76
- var init_remark_exports = __esm({
77
- "src/mdx-plugins/remark-exports.ts"() {
78
- "use strict";
79
- import_estree_util_value_to_estree = require("estree-util-value-to-estree");
80
- }
81
- });
82
-
83
- // src/mdx-plugins/remark-extract.ts
84
- function remarkExtract() {
85
- return (tree, file) => {
86
- const urls = [];
87
- (0, import_unist_util_visit2.visit)(tree, "link", (node) => {
88
- urls.push({
89
- href: node.url
90
- });
91
- return "skip";
92
- });
93
- file.data.extractedReferences = urls;
94
- };
95
- }
96
- var import_unist_util_visit2;
97
- var init_remark_extract = __esm({
98
- "src/mdx-plugins/remark-extract.ts"() {
101
+ var import_unist_util_visit2, import_estree_util_value_to_estree;
102
+ var init_remark_postprocess = __esm({
103
+ "src/mdx-plugins/remark-postprocess.ts"() {
99
104
  "use strict";
100
105
  import_unist_util_visit2 = require("unist-util-visit");
106
+ import_estree_util_value_to_estree = require("estree-util-value-to-estree");
101
107
  }
102
108
  });
103
109
 
@@ -156,12 +162,14 @@ function getDefaultMDXOptions({
156
162
  ],
157
163
  "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
158
164
  ...v,
159
- remarkExtract,
160
165
  remarkStructureOptions !== false && [
161
166
  plugins.remarkStructure,
162
167
  remarkStructureOptions
163
168
  ],
164
- [remarkMdxExport, { values: mdxExports }]
169
+ [
170
+ remarkPostprocess,
171
+ { injectExports: mdxExports }
172
+ ]
165
173
  ],
166
174
  mdxOptions.remarkPlugins
167
175
  );
@@ -185,8 +193,7 @@ var init_mdx_options = __esm({
185
193
  "src/utils/mdx-options.ts"() {
186
194
  "use strict";
187
195
  plugins = __toESM(require("fumadocs-core/mdx-plugins"), 1);
188
- init_remark_exports();
189
- init_remark_extract();
196
+ init_remark_postprocess();
190
197
  }
191
198
  });
192
199
 
@@ -275,6 +282,7 @@ function resolveFiles({ docs, meta }) {
275
282
  var import_mdx = require("@mdx-js/mdx");
276
283
 
277
284
  // src/mdx-plugins/remark-include.ts
285
+ var import_unified = require("unified");
278
286
  var import_unist_util_visit = require("unist-util-visit");
279
287
  var path = __toESM(require("path"), 1);
280
288
  var fs2 = __toESM(require("fs/promises"), 1);
@@ -296,6 +304,10 @@ function fumaMatter(input) {
296
304
  }
297
305
 
298
306
  // src/mdx-plugins/remark-include.ts
307
+ var import_remark_parse = __toESM(require("remark-parse"), 1);
308
+ var import_remark_mdx = __toESM(require("remark-mdx"), 1);
309
+ var import_mdx_plugins = require("fumadocs-core/mdx-plugins");
310
+ var baseProcessor = (0, import_unified.unified)().use(import_mdx_plugins.remarkHeading);
299
311
  function flattenNode(node) {
300
312
  if ("children" in node)
301
313
  return node.children.map((child) => flattenNode(child)).join("");
@@ -311,86 +323,96 @@ function parseSpecifier(specifier) {
311
323
  };
312
324
  }
313
325
  function extractSection(root, section) {
326
+ let nodes;
314
327
  for (const node of root.children) {
315
328
  if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
316
329
  (attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
317
330
  )) {
318
- return {
319
- type: "root",
320
- children: node.children
321
- };
331
+ nodes = node.children;
332
+ break;
333
+ }
334
+ if (node.type === "heading" && node.data?.hProperties?.id === section) {
335
+ nodes = [node];
336
+ continue;
322
337
  }
338
+ if (!nodes) continue;
339
+ if (node.type === "heading") break;
340
+ nodes.push(node);
323
341
  }
342
+ if (nodes)
343
+ return {
344
+ type: "root",
345
+ children: nodes
346
+ };
324
347
  }
325
348
  function remarkInclude() {
326
349
  const TagName = "include";
350
+ async function embedContent(file, heading, params, data) {
351
+ let content;
352
+ try {
353
+ content = (await fs2.readFile(file)).toString();
354
+ } catch (e) {
355
+ throw new Error(
356
+ `failed to read file ${file}
357
+ ${e instanceof Error ? e.message : String(e)}`,
358
+ { cause: e }
359
+ );
360
+ }
361
+ const ext = path.extname(file);
362
+ data._compiler?.addDependency(file);
363
+ if (params.lang || ext !== ".md" && ext !== ".mdx") {
364
+ const lang = params.lang ?? ext.slice(1);
365
+ return {
366
+ type: "code",
367
+ lang,
368
+ meta: params.meta,
369
+ value: content,
370
+ data: {}
371
+ };
372
+ }
373
+ const processor = (data._getProcessor ?? getDefaultProcessor)(
374
+ ext === ".mdx" ? "mdx" : "md"
375
+ );
376
+ let parsed = await baseProcessor.run(
377
+ processor.parse(fumaMatter(content).content)
378
+ );
379
+ if (heading) {
380
+ const extracted = extractSection(parsed, heading);
381
+ if (!extracted)
382
+ throw new Error(
383
+ `Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
384
+ );
385
+ parsed = extracted;
386
+ }
387
+ await update(parsed, path.dirname(file), data);
388
+ return parsed;
389
+ }
327
390
  async function update(tree, directory, data) {
328
391
  const queue = [];
329
392
  (0, import_unist_util_visit.visit)(
330
393
  tree,
331
394
  ["mdxJsxFlowElement", "mdxJsxTextElement"],
332
- (node, _, parent) => {
333
- let specifier;
395
+ (_node, _, parent) => {
396
+ const node = _node;
397
+ if (node.name !== TagName) return;
334
398
  const params = {};
335
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
336
- const value = flattenNode(node);
337
- if (value.length > 0) {
338
- for (const attr of node.attributes) {
339
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
340
- params[attr.name] = attr.value;
341
- }
342
- }
343
- specifier = value;
399
+ const specifier = flattenNode(node);
400
+ if (specifier.length === 0) return "skip";
401
+ for (const attr of node.attributes) {
402
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
403
+ params[attr.name] = attr.value;
344
404
  }
345
405
  }
346
- if (!specifier) return;
347
- const { file, section } = parseSpecifier(specifier);
348
- const targetPath = path.resolve(
406
+ const { file: relativePath, section } = parseSpecifier(specifier);
407
+ const file = path.resolve(
349
408
  "cwd" in params ? process.cwd() : directory,
350
- file
409
+ relativePath
351
410
  );
352
- const asCode = params.lang || !file.endsWith(".md") && !file.endsWith(".mdx");
353
411
  queue.push(
354
- fs2.readFile(targetPath).then((buffer) => buffer.toString()).then(async (content) => {
355
- data._compiler?.addDependency(targetPath);
356
- if (asCode) {
357
- const lang = params.lang ?? path.extname(file).slice(1);
358
- Object.assign(node, {
359
- type: "code",
360
- lang,
361
- meta: params.meta,
362
- value: content,
363
- data: {}
364
- });
365
- return;
366
- }
367
- const processor = data._processor ? data._processor.getProcessor(
368
- targetPath.endsWith(".md") ? "md" : "mdx"
369
- ) : this;
370
- let parsed = processor.parse(fumaMatter(content).content);
371
- if (section) {
372
- const extracted = extractSection(parsed, section);
373
- if (!extracted)
374
- throw new Error(
375
- `Cannot find section ${section} in ${file}, make sure you have encapsulated the section in a <section id="${section}"> tag`
376
- );
377
- parsed = extracted;
378
- }
379
- await update.call(
380
- processor,
381
- parsed,
382
- path.dirname(targetPath),
383
- data
384
- );
412
+ embedContent(file, section, params, data).then((replace) => {
385
413
  Object.assign(
386
414
  parent && parent.type === "paragraph" ? parent : node,
387
- parsed
388
- );
389
- }).catch((e) => {
390
- throw new Error(
391
- `failed to read file ${targetPath}
392
- ${e instanceof Error ? e.message : String(e)}`,
393
- { cause: e }
415
+ replace
394
416
  );
395
417
  })
396
418
  );
@@ -400,9 +422,14 @@ ${e instanceof Error ? e.message : String(e)}`,
400
422
  await Promise.all(queue);
401
423
  }
402
424
  return async (tree, file) => {
403
- await update.call(this, tree, path.dirname(file.path), file.data);
425
+ await update(tree, path.dirname(file.path), file.data);
404
426
  };
405
427
  }
428
+ function getDefaultProcessor(format) {
429
+ const mdProcessor = (0, import_unified.unified)().use(import_remark_parse.default);
430
+ if (format === "md") return mdProcessor;
431
+ return mdProcessor.use(import_remark_mdx.default);
432
+ }
406
433
 
407
434
  // src/utils/build-mdx.ts
408
435
  var cache2 = /* @__PURE__ */ new Map();
@@ -431,9 +458,7 @@ async function buildMDX(cacheKey, source, options) {
431
458
  ...data,
432
459
  frontmatter,
433
460
  _compiler,
434
- _processor: {
435
- getProcessor
436
- }
461
+ _getProcessor: getProcessor
437
462
  }
438
463
  });
439
464
  }
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-DvnkeVI3.cjs';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-B2kQsHs7.cjs';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-DnJzAZrj.cjs';
4
+ import '../define-DAZmbu3U.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';
@@ -1,12 +1,12 @@
1
- import { L as LoadedConfig, a as RuntimeAsync } from '../types-zBRxlyaM.js';
1
+ import { L as LoadedConfig, a as RuntimeAsync } from '../types-CkmezNbX.js';
2
2
  import '@standard-schema/spec';
3
3
  import 'fumadocs-core/source';
4
- import '../define-DnJzAZrj.js';
4
+ import '../define-DAZmbu3U.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';
@@ -4,11 +4,11 @@ import {
4
4
  } from "../chunk-NUDEC6C5.js";
5
5
  import {
6
6
  buildMDX
7
- } from "../chunk-7JFPDRW7.js";
8
- import "../chunk-IGXZS2W6.js";
7
+ } from "../chunk-QQWCBFFE.js";
9
8
  import {
10
9
  buildConfig
11
- } from "../chunk-S73DGUHI.js";
10
+ } from "../chunk-QVZ7JH4H.js";
11
+ import "../chunk-SVTXMVLQ.js";
12
12
  import "../chunk-VWJKRQZR.js";
13
13
 
14
14
  // src/runtime/async.ts
@@ -1,9 +1,9 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
  import { MDXProps } from 'mdx/types';
3
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../define-DnJzAZrj.cjs';
3
+ import { D as DocCollection, a as DocsCollection, M as MetaCollection } from '../define-DAZmbu3U.cjs';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
5
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
6
- import { C as CompiledMDXProperties } from '../build-mdx-DMe0r3s_.cjs';
6
+ import { C as CompiledMDXProperties } from '../build-mdx-DnC1jKvn.cjs';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
@@ -1,9 +1,9 @@
1
1
  import { FC, ReactNode } from 'react';
2
2
  import { MDXProps } from 'mdx/types';
3
- import { a as DocCollection, b as DocsCollection, M as MetaCollection } from '../define-DnJzAZrj.js';
3
+ import { D as DocCollection, a as DocsCollection, M as MetaCollection } from '../define-DAZmbu3U.js';
4
4
  import { StandardSchemaV1 } from '@standard-schema/spec';
5
5
  import { PageData, MetaData, Source } from 'fumadocs-core/source';
6
- import { C as CompiledMDXProperties } from '../build-mdx-DMe0r3s_.js';
6
+ import { C as CompiledMDXProperties } from '../build-mdx-DnC1jKvn.js';
7
7
  import 'fumadocs-core/mdx-plugins';
8
8
  import '@mdx-js/mdx';
9
9
  import 'unified';
@@ -1,8 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-DnJzAZrj.cjs';
3
+ import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig } from './define-DAZmbu3U.cjs';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { C as CompiledMDXProperties } from './build-mdx-DMe0r3s_.cjs';
5
+ import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.cjs';
6
6
 
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;
@@ -1,8 +1,8 @@
1
1
  import { StandardSchemaV1 } from '@standard-schema/spec';
2
2
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
3
- import { a as DocCollection, M as MetaCollection, b as DocsCollection, G as GlobalConfig } from './define-DnJzAZrj.js';
3
+ import { D as DocCollection, M as MetaCollection, a as DocsCollection, G as GlobalConfig } from './define-DAZmbu3U.js';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
5
- import { C as CompiledMDXProperties } from './build-mdx-DMe0r3s_.js';
5
+ import { C as CompiledMDXProperties } from './build-mdx-DnC1jKvn.js';
6
6
 
7
7
  interface LoadedConfig {
8
8
  collections: Map<string, DocCollection | MetaCollection | DocsCollection>;