fumadocs-mdx 11.3.0 → 11.3.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.
@@ -0,0 +1,53 @@
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
+ };
@@ -201,35 +201,47 @@ var path = __toESM(require("path"), 1);
201
201
  var fs = __toESM(require("fs/promises"), 1);
202
202
  var import_gray_matter = __toESM(require("gray-matter"), 1);
203
203
  function remarkInclude() {
204
- return async (tree, file) => {
204
+ const TagName = "include";
205
+ async function update(tree, file, processor, compiler) {
205
206
  const queue = [];
206
207
  (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
207
208
  let specifier;
208
209
  if (node.type === "paragraph" && node.children.length === 3) {
209
210
  const [open, content, closure] = node.children;
210
- if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
211
+ if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
211
212
  specifier = content.value.trim();
212
213
  }
214
+ } else if (node.type === "paragraph" && node.children.length === 1) {
215
+ const child = node.children[0];
216
+ if (child.type === "mdxJsxTextElement" && child.name === TagName) {
217
+ const text = child.children.at(0);
218
+ if (text && text.type === "text") {
219
+ specifier = text.value;
220
+ }
221
+ }
213
222
  }
214
- if (node.type === "mdxJsxFlowElement" && node.name === "include") {
223
+ if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
215
224
  const child = node.children.at(0);
216
- if (!child || child.type !== "text") return;
217
- specifier = child.value;
225
+ if (child && child.type === "text") {
226
+ specifier = child.value;
227
+ }
218
228
  }
219
- if (!specifier) return "skip";
220
- const targetPath = path.resolve(path.dirname(file.path), specifier);
229
+ if (!specifier) return;
230
+ const targetPath = path.resolve(path.dirname(file), specifier);
221
231
  queue.push(
222
- fs.readFile(targetPath).then((content) => {
223
- const parsed = this.parse((0, import_gray_matter.default)(content).content);
224
- if (file.data._compiler) {
225
- file.data._compiler.addDependency(targetPath);
226
- }
232
+ fs.readFile(targetPath).then(async (content) => {
233
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
234
+ compiler?.addDependency(targetPath);
235
+ await update(parsed, targetPath, processor, compiler);
227
236
  Object.assign(node, parsed);
228
237
  })
229
238
  );
230
239
  return "skip";
231
240
  });
232
241
  await Promise.all(queue);
242
+ }
243
+ return async (tree, file) => {
244
+ await update(tree, file.path, this, file.data._compiler);
233
245
  };
234
246
  }
235
247
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkInclude
3
- } from "../chunk-GUHWD47S.js";
3
+ } from "../chunk-PY2KKTR2.js";
4
4
  import {
5
5
  getDefaultMDXOptions
6
6
  } from "../chunk-6LEQ23AC.js";
@@ -272,35 +272,47 @@ var path2 = __toESM(require("path"), 1);
272
272
  var fs2 = __toESM(require("fs/promises"), 1);
273
273
  var import_gray_matter = __toESM(require("gray-matter"), 1);
274
274
  function remarkInclude() {
275
- return async (tree, file) => {
275
+ const TagName = "include";
276
+ async function update(tree, file, processor, compiler) {
276
277
  const queue = [];
277
278
  (0, import_unist_util_visit.visit)(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
278
279
  let specifier;
279
280
  if (node.type === "paragraph" && node.children.length === 3) {
280
281
  const [open, content, closure] = node.children;
281
- if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
282
+ if (open.type === "html" && open.value === `<${TagName}>` && content.type === "text" && closure.type === "html" && closure.value === `</${TagName}>`) {
282
283
  specifier = content.value.trim();
283
284
  }
285
+ } else if (node.type === "paragraph" && node.children.length === 1) {
286
+ const child = node.children[0];
287
+ if (child.type === "mdxJsxTextElement" && child.name === TagName) {
288
+ const text = child.children.at(0);
289
+ if (text && text.type === "text") {
290
+ specifier = text.value;
291
+ }
292
+ }
284
293
  }
285
- if (node.type === "mdxJsxFlowElement" && node.name === "include") {
294
+ if (node.type === "mdxJsxFlowElement" && node.name === TagName) {
286
295
  const child = node.children.at(0);
287
- if (!child || child.type !== "text") return;
288
- specifier = child.value;
296
+ if (child && child.type === "text") {
297
+ specifier = child.value;
298
+ }
289
299
  }
290
- if (!specifier) return "skip";
291
- const targetPath = path2.resolve(path2.dirname(file.path), specifier);
300
+ if (!specifier) return;
301
+ const targetPath = path2.resolve(path2.dirname(file), specifier);
292
302
  queue.push(
293
- fs2.readFile(targetPath).then((content) => {
294
- const parsed = this.parse((0, import_gray_matter.default)(content).content);
295
- if (file.data._compiler) {
296
- file.data._compiler.addDependency(targetPath);
297
- }
303
+ fs2.readFile(targetPath).then(async (content) => {
304
+ const parsed = processor.parse((0, import_gray_matter.default)(content).content);
305
+ compiler?.addDependency(targetPath);
306
+ await update(parsed, targetPath, processor, compiler);
298
307
  Object.assign(node, parsed);
299
308
  })
300
309
  );
301
310
  return "skip";
302
311
  });
303
312
  await Promise.all(queue);
313
+ }
314
+ return async (tree, file) => {
315
+ await update(tree, file.path, this, file.data._compiler);
304
316
  };
305
317
  }
306
318
 
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  remarkInclude
3
- } from "./chunk-GUHWD47S.js";
3
+ } from "./chunk-PY2KKTR2.js";
4
4
  import {
5
5
  getConfigHash,
6
6
  loadConfigCached
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.3.0",
3
+ "version": "11.3.1",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -54,15 +54,15 @@
54
54
  "@types/mdast": "^4.0.3",
55
55
  "@types/mdx": "^2.0.13",
56
56
  "@types/micromatch": "^4.0.9",
57
- "@types/react": "^19.0.4",
58
- "mdast-util-mdx-jsx": "^3.1.3",
57
+ "@types/react": "^19.0.7",
58
+ "mdast-util-mdx-jsx": "^3.2.0",
59
59
  "next": "^15.1.4",
60
60
  "unified": "^11.0.5",
61
61
  "vfile": "^6.0.3",
62
62
  "webpack": "^5.97.1",
63
63
  "eslint-config-custom": "0.0.0",
64
- "tsconfig": "0.0.0",
65
- "fumadocs-core": "14.7.2"
64
+ "fumadocs-core": "14.7.4",
65
+ "tsconfig": "0.0.0"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "fumadocs-core": "^14.0.0",
@@ -1,41 +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
- return async (tree, file) => {
8
- const queue = [];
9
- visit(tree, ["mdxJsxFlowElement", "paragraph"], (node) => {
10
- let specifier;
11
- if (node.type === "paragraph" && node.children.length === 3) {
12
- const [open, content, closure] = node.children;
13
- if (open.type === "html" && open.value === "<include>" && content.type === "text" && closure.type === "html" && closure.value === "</include>") {
14
- specifier = content.value.trim();
15
- }
16
- }
17
- if (node.type === "mdxJsxFlowElement" && node.name === "include") {
18
- const child = node.children.at(0);
19
- if (!child || child.type !== "text") return;
20
- specifier = child.value;
21
- }
22
- if (!specifier) return "skip";
23
- const targetPath = path.resolve(path.dirname(file.path), specifier);
24
- queue.push(
25
- fs.readFile(targetPath).then((content) => {
26
- const parsed = this.parse(matter(content).content);
27
- if (file.data._compiler) {
28
- file.data._compiler.addDependency(targetPath);
29
- }
30
- Object.assign(node, parsed);
31
- })
32
- );
33
- return "skip";
34
- });
35
- await Promise.all(queue);
36
- };
37
- }
38
-
39
- export {
40
- remarkInclude
41
- };