fumadocs-mdx 11.5.6 → 11.5.7

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.
@@ -0,0 +1,68 @@
1
+ // src/mdx-plugins/remark-include.ts
2
+ import { visit } from "unist-util-visit";
3
+ import * as path from "node:path";
4
+ import * as fs from "node:fs/promises";
5
+ import matter from "gray-matter";
6
+ function flattenNode(node) {
7
+ if ("children" in node)
8
+ return node.children.map((child) => flattenNode(child)).join("");
9
+ if ("value" in node) return node.value;
10
+ return "";
11
+ }
12
+ function remarkInclude() {
13
+ const TagName = "include";
14
+ async function update(tree, file, processor, compiler) {
15
+ const queue = [];
16
+ visit(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
17
+ let specifier;
18
+ const params = {};
19
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
20
+ const value = flattenNode(node);
21
+ if (value.length > 0) {
22
+ for (const attr of node.attributes) {
23
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
24
+ params[attr.name] = attr.value;
25
+ }
26
+ }
27
+ specifier = value;
28
+ }
29
+ }
30
+ if (!specifier) return;
31
+ const targetPath = path.resolve(
32
+ "cwd" in params ? process.cwd() : path.dirname(file),
33
+ specifier
34
+ );
35
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
36
+ queue.push(
37
+ fs.readFile(targetPath).then(async (content) => {
38
+ compiler?.addDependency(targetPath);
39
+ if (asCode) {
40
+ const lang = params.lang ?? path.extname(specifier).slice(1);
41
+ Object.assign(node, {
42
+ type: "code",
43
+ lang,
44
+ meta: params.meta,
45
+ value: content.toString(),
46
+ data: {}
47
+ });
48
+ return;
49
+ }
50
+ const parsed = processor.parse(matter(content).content);
51
+ await update(parsed, targetPath, processor, compiler);
52
+ Object.assign(node, parsed);
53
+ }).catch((e) => {
54
+ console.warn(`failed to read file: ${targetPath}`, e);
55
+ })
56
+ );
57
+ return "skip";
58
+ });
59
+ await Promise.all(queue);
60
+ }
61
+ return async (tree, file) => {
62
+ await update(tree, file.path, this, file.data._compiler);
63
+ };
64
+ }
65
+
66
+ export {
67
+ remarkInclude
68
+ };
@@ -209,40 +209,55 @@ var import_unist_util_visit = require("unist-util-visit");
209
209
  var path = __toESM(require("path"), 1);
210
210
  var fs = __toESM(require("fs/promises"), 1);
211
211
  var import_gray_matter = __toESM(require("gray-matter"), 1);
212
+ function flattenNode(node) {
213
+ if ("children" in node)
214
+ return node.children.map((child) => flattenNode(child)).join("");
215
+ if ("value" in node) return node.value;
216
+ return "";
217
+ }
212
218
  function remarkInclude() {
213
219
  const TagName = "include";
214
220
  async function update(tree, file, processor, compiler) {
215
221
  const queue = [];
216
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
222
+ (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
217
223
  let specifier;
218
- if (node.type === "paragraph" && node.children.length === 3) {
219
- const [open, content, closure] = node.children;
220
- if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
221
- specifier = content.value.trim();
222
- }
223
- } else if (node.type === "paragraph" && node.children.length === 1) {
224
- const child = node.children[0];
225
- if (child.type === "mdxJsxTextElement" && child.name === TagName) {
226
- const text = child.children.at(0);
227
- if (text && text.type === "text") {
228
- specifier = text.value;
224
+ const params = {};
225
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
226
+ const value = flattenNode(node);
227
+ if (value.length > 0) {
228
+ for (const attr of node.attributes) {
229
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
230
+ params[attr.name] = attr.value;
231
+ }
229
232
  }
230
- }
231
- }
232
- if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
233
- const child = node.children.at(0);
234
- if (child && child.type === "text") {
235
- specifier = child.value;
233
+ specifier = value;
236
234
  }
237
235
  }
238
236
  if (!specifier) return;
239
- const targetPath = path.resolve(path.dirname(file), specifier);
237
+ const targetPath = path.resolve(
238
+ "cwd" in params ? process.cwd() : path.dirname(file),
239
+ specifier
240
+ );
241
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
240
242
  queue.push(
241
243
  fs.readFile(targetPath).then(async (content) => {
242
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
243
244
  compiler?.addDependency(targetPath);
245
+ if (asCode) {
246
+ const lang = params.lang ?? path.extname(specifier).slice(1);
247
+ Object.assign(node, {
248
+ type: "code",
249
+ lang,
250
+ meta: params.meta,
251
+ value: content.toString(),
252
+ data: {}
253
+ });
254
+ return;
255
+ }
256
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
244
257
  await update(parsed, targetPath, processor, compiler);
245
258
  Object.assign(node, parsed);
259
+ }).catch((e) => {
260
+ console.warn(`failed to read file: ${targetPath}`, e);
246
261
  })
247
262
  );
248
263
  return "skip";
@@ -1,4 +1,4 @@
1
- export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-DxwgTgV6.cjs';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-P0QTVn7W.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -1,4 +1,4 @@
1
- export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-DxwgTgV6.js';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, h as DefaultMDXOptions, D as DocCollection, c as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, d as defineCollections, g as defineConfig, e as defineDocs, f as frontmatterSchema, i as getDefaultMDXOptions, m as metaSchema } from '../define-P0QTVn7W.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
4
  import '@mdx-js/mdx';
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-KGLACICA.js";
5
5
  import {
6
6
  remarkInclude
7
- } from "../chunk-PY2KKTR2.js";
7
+ } from "../chunk-ITGWT23S.js";
8
8
  import {
9
9
  getDefaultMDXOptions
10
10
  } from "../chunk-IOENRFUX.js";
@@ -34,13 +34,6 @@ interface GlobalConfig {
34
34
  * @defaultValue 'none'
35
35
  */
36
36
  lastModifiedTime?: 'git' | 'none';
37
- /**
38
- * Generate manifest file on build mode
39
- *
40
- * @defaultValue false
41
- * @deprecated No longer needed, use a route handler to export build time info
42
- */
43
- generateManifest?: boolean;
44
37
  }
45
38
  interface FileInfo {
46
39
  path: string;
@@ -34,13 +34,6 @@ interface GlobalConfig {
34
34
  * @defaultValue 'none'
35
35
  */
36
36
  lastModifiedTime?: 'git' | 'none';
37
- /**
38
- * Generate manifest file on build mode
39
- *
40
- * @defaultValue false
41
- * @deprecated No longer needed, use a route handler to export build time info
42
- */
43
- generateManifest?: boolean;
44
37
  }
45
38
  interface FileInfo {
46
39
  path: string;
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-DxwgTgV6.cjs';
3
- import { R as Runtime } from './types-BIA23Xld.cjs';
4
- export { a as RuntimeFile } from './types-BIA23Xld.cjs';
2
+ import { B as BaseCollectionEntry } from './define-P0QTVn7W.cjs';
3
+ import { R as Runtime } from './types-bWXuqsw9.cjs';
4
+ export { a as RuntimeFile } from './types-bWXuqsw9.cjs';
5
5
  import '@mdx-js/mdx';
6
6
  import 'mdx/types';
7
7
  import 'fumadocs-core/mdx-plugins';
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-DxwgTgV6.js';
3
- import { R as Runtime } from './types-2R3kLFSi.js';
4
- export { a as RuntimeFile } from './types-2R3kLFSi.js';
2
+ import { B as BaseCollectionEntry } from './define-P0QTVn7W.js';
3
+ import { R as Runtime } from './types-CJRGJLAg.js';
4
+ export { a as RuntimeFile } from './types-CJRGJLAg.js';
5
5
  import '@mdx-js/mdx';
6
6
  import 'mdx/types';
7
7
  import 'fumadocs-core/mdx-plugins';
@@ -263,40 +263,55 @@ var import_unist_util_visit = require("unist-util-visit");
263
263
  var path2 = __toESM(require("path"), 1);
264
264
  var fs2 = __toESM(require("fs/promises"), 1);
265
265
  var import_gray_matter = __toESM(require("gray-matter"), 1);
266
+ function flattenNode(node) {
267
+ if ("children" in node)
268
+ return node.children.map((child) => flattenNode(child)).join("");
269
+ if ("value" in node) return node.value;
270
+ return "";
271
+ }
266
272
  function remarkInclude() {
267
273
  const TagName = "include";
268
274
  async function update(tree, file, processor, compiler) {
269
275
  const queue = [];
270
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
276
+ (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
271
277
  let specifier;
272
- if (node.type === "paragraph" && node.children.length === 3) {
273
- const [open, content, closure] = node.children;
274
- if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
275
- specifier = content.value.trim();
276
- }
277
- } else if (node.type === "paragraph" && node.children.length === 1) {
278
- const child = node.children[0];
279
- if (child.type === "mdxJsxTextElement" && child.name === TagName) {
280
- const text = child.children.at(0);
281
- if (text && text.type === "text") {
282
- specifier = text.value;
278
+ const params = {};
279
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
280
+ const value = flattenNode(node);
281
+ if (value.length > 0) {
282
+ for (const attr of node.attributes) {
283
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
284
+ params[attr.name] = attr.value;
285
+ }
283
286
  }
284
- }
285
- }
286
- if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
287
- const child = node.children.at(0);
288
- if (child && child.type === "text") {
289
- specifier = child.value;
287
+ specifier = value;
290
288
  }
291
289
  }
292
290
  if (!specifier) return;
293
- const targetPath = path2.resolve(path2.dirname(file), specifier);
291
+ const targetPath = path2.resolve(
292
+ "cwd" in params ? process.cwd() : path2.dirname(file),
293
+ specifier
294
+ );
295
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
294
296
  queue.push(
295
297
  fs2.readFile(targetPath).then(async (content) => {
296
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
297
298
  compiler?.addDependency(targetPath);
299
+ if (asCode) {
300
+ const lang = params.lang ?? path2.extname(specifier).slice(1);
301
+ Object.assign(node, {
302
+ type: "code",
303
+ lang,
304
+ meta: params.meta,
305
+ value: content.toString(),
306
+ data: {}
307
+ });
308
+ return;
309
+ }
310
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
298
311
  await update(parsed, targetPath, processor, compiler);
299
312
  Object.assign(node, parsed);
313
+ }).catch((e) => {
314
+ console.warn(`failed to read file: ${targetPath}`, e);
300
315
  })
301
316
  );
302
317
  return "skip";
@@ -7,7 +7,7 @@ import {
7
7
  } from "./chunk-KGLACICA.js";
8
8
  import {
9
9
  remarkInclude
10
- } from "./chunk-PY2KKTR2.js";
10
+ } from "./chunk-ITGWT23S.js";
11
11
  import "./chunk-SLCPEEMF.js";
12
12
 
13
13
  // src/loader-mdx.ts
@@ -42,40 +42,55 @@ var import_unist_util_visit = require("unist-util-visit");
42
42
  var path = __toESM(require("path"), 1);
43
43
  var fs = __toESM(require("fs/promises"), 1);
44
44
  var import_gray_matter = __toESM(require("gray-matter"), 1);
45
+ function flattenNode(node) {
46
+ if ("children" in node)
47
+ return node.children.map((child) => flattenNode(child)).join("");
48
+ if ("value" in node) return node.value;
49
+ return "";
50
+ }
45
51
  function remarkInclude() {
46
52
  const TagName = "include";
47
53
  async function update(tree, file, processor, compiler) {
48
54
  const queue = [];
49
- (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
55
+ (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "mdxJsxTextElement"], (node) => {
50
56
  let specifier;
51
- if (node.type === "paragraph" && node.children.length === 3) {
52
- const [open, content, closure] = node.children;
53
- if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
54
- specifier = content.value.trim();
55
- }
56
- } else if (node.type === "paragraph" && node.children.length === 1) {
57
- const child = node.children[0];
58
- if (child.type === "mdxJsxTextElement" && child.name === TagName) {
59
- const text = child.children.at(0);
60
- if (text && text.type === "text") {
61
- specifier = text.value;
57
+ const params = {};
58
+ if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
59
+ const value = flattenNode(node);
60
+ if (value.length > 0) {
61
+ for (const attr of node.attributes) {
62
+ if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
63
+ params[attr.name] = attr.value;
64
+ }
62
65
  }
63
- }
64
- }
65
- if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
66
- const child = node.children.at(0);
67
- if (child && child.type === "text") {
68
- specifier = child.value;
66
+ specifier = value;
69
67
  }
70
68
  }
71
69
  if (!specifier) return;
72
- const targetPath = path.resolve(path.dirname(file), specifier);
70
+ const targetPath = path.resolve(
71
+ "cwd" in params ? process.cwd() : path.dirname(file),
72
+ specifier
73
+ );
74
+ const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
73
75
  queue.push(
74
76
  fs.readFile(targetPath).then(async (content) => {
75
- const parsed = processor.parse((0, import_gray_matter.default)(content).content);
76
77
  compiler?.addDependency(targetPath);
78
+ if (asCode) {
79
+ const lang = params.lang ?? path.extname(specifier).slice(1);
80
+ Object.assign(node, {
81
+ type: "code",
82
+ lang,
83
+ meta: params.meta,
84
+ value: content.toString(),
85
+ data: {}
86
+ });
87
+ return;
88
+ }
89
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
77
90
  await update(parsed, targetPath, processor, compiler);
78
91
  Object.assign(node, parsed);
92
+ }).catch((e) => {
93
+ console.warn(`failed to read file: ${targetPath}`, e);
79
94
  })
80
95
  );
81
96
  return "skip";
@@ -1,5 +1,5 @@
1
- import { L as LoadedConfig, b as RuntimeAsync } from '../types-BIA23Xld.cjs';
2
- import '../define-DxwgTgV6.cjs';
1
+ import { L as LoadedConfig, b as RuntimeAsync } from '../types-bWXuqsw9.cjs';
2
+ import '../define-P0QTVn7W.cjs';
3
3
  import '@mdx-js/mdx';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -1,5 +1,5 @@
1
- import { L as LoadedConfig, b as RuntimeAsync } from '../types-2R3kLFSi.js';
2
- import '../define-DxwgTgV6.js';
1
+ import { L as LoadedConfig, b as RuntimeAsync } from '../types-CJRGJLAg.js';
2
+ import '../define-P0QTVn7W.js';
3
3
  import '@mdx-js/mdx';
4
4
  import 'mdx/types';
5
5
  import 'fumadocs-core/mdx-plugins';
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-IZURUUPO.js";
5
5
  import {
6
6
  remarkInclude
7
- } from "../chunk-PY2KKTR2.js";
7
+ } from "../chunk-ITGWT23S.js";
8
8
  import {
9
9
  buildConfig
10
10
  } from "../chunk-SLCPEEMF.js";
@@ -1,4 +1,4 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-DxwgTgV6.js';
1
+ import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-P0QTVn7W.js';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
@@ -1,4 +1,4 @@
1
- import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-DxwgTgV6.cjs';
1
+ import { D as DocCollection, b as MetaCollection, c as DocsCollection, G as GlobalConfig, F as FileInfo, M as MarkdownProps, B as BaseCollectionEntry } from './define-P0QTVn7W.cjs';
2
2
  import { StandardSchemaV1 } from '@standard-schema/spec';
3
3
  import { Source, PageData, MetaData } from 'fumadocs-core/source';
4
4
  import { ProcessorOptions } from '@mdx-js/mdx';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.5.6",
3
+ "version": "11.5.7",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -57,15 +57,15 @@
57
57
  "@types/cross-spawn": "^6.0.6",
58
58
  "@types/mdast": "^4.0.3",
59
59
  "@types/mdx": "^2.0.13",
60
- "@types/react": "^19.0.9",
60
+ "@types/react": "^19.0.11",
61
61
  "mdast-util-mdx-jsx": "^3.2.0",
62
- "next": "^15.1.7",
62
+ "next": "^15.2.3",
63
63
  "unified": "^11.0.5",
64
64
  "vfile": "^6.0.3",
65
65
  "webpack": "^5.97.1",
66
- "@fumadocs/mdx-remote": "1.2.0",
66
+ "@fumadocs/mdx-remote": "1.2.1",
67
67
  "eslint-config-custom": "0.0.0",
68
- "fumadocs-core": "15.0.9",
68
+ "fumadocs-core": "15.1.1",
69
69
  "tsconfig": "0.0.0"
70
70
  },
71
71
  "peerDependencies": {
@@ -1,53 +0,0 @@
1
- // src/mdx-plugins/remark-include.ts
2
- import { visit } from "unist-util-visit";
3
- import * as path from "node:path";
4
- import * as fs from "node:fs/promises";
5
- import matter from "gray-matter";
6
- function remarkInclude() {
7
- const TagName = "include";
8
- async function update(tree, file, processor, compiler) {
9
- const queue = [];
10
- visit(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
11
- let specifier;
12
- if (node.type === "paragraph" && node.children.length === 3) {
13
- const [open, content, closure] = node.children;
14
- if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
15
- specifier = content.value.trim();
16
- }
17
- } else if (node.type === "paragraph" && node.children.length === 1) {
18
- const child = node.children[0];
19
- if (child.type === "mdxJsxTextElement" && child.name === TagName) {
20
- const text = child.children.at(0);
21
- if (text && text.type === "text") {
22
- specifier = text.value;
23
- }
24
- }
25
- }
26
- if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
27
- const child = node.children.at(0);
28
- if (child && child.type === "text") {
29
- specifier = child.value;
30
- }
31
- }
32
- if (!specifier) return;
33
- const targetPath = path.resolve(path.dirname(file), specifier);
34
- queue.push(
35
- fs.readFile(targetPath).then(async (content) => {
36
- const parsed = processor.parse(matter(content).content);
37
- compiler?.addDependency(targetPath);
38
- await update(parsed, targetPath, processor, compiler);
39
- Object.assign(node, parsed);
40
- })
41
- );
42
- return "skip";
43
- });
44
- await Promise.all(queue);
45
- }
46
- return async (tree, file) => {
47
- await update(tree, file.path, this, file.data._compiler);
48
- };
49
- }
50
-
51
- export {
52
- remarkInclude
53
- };