fumadocs-mdx 11.6.0 → 13.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.
Files changed (93) hide show
  1. package/dist/bin.cjs +1728 -0
  2. package/dist/bin.d.cts +1 -0
  3. package/dist/bin.d.ts +1 -0
  4. package/dist/bin.js +16 -0
  5. package/dist/build-mdx-CCNr86q6.d.ts +53 -0
  6. package/dist/build-mdx-D-r3_eQL.d.cts +53 -0
  7. package/dist/bun/index.cjs +857 -0
  8. package/dist/bun/index.d.cts +13 -0
  9. package/dist/bun/index.d.ts +13 -0
  10. package/dist/bun/index.js +62 -0
  11. package/dist/chunk-3J3WL7WN.js +160 -0
  12. package/dist/chunk-CXA4JO4Z.js +45 -0
  13. package/dist/chunk-EELYB2XC.js +207 -0
  14. package/dist/chunk-FSZMKRVH.js +80 -0
  15. package/dist/chunk-II3H5ZVZ.js +77 -0
  16. package/dist/chunk-JVZFH6ND.js +40 -0
  17. package/dist/chunk-K5ZLPEIQ.js +207 -0
  18. package/dist/{chunk-VFALQK6O.js → chunk-KILFIBVW.js} +21 -12
  19. package/dist/chunk-NVRDCY6Z.js +30 -0
  20. package/dist/chunk-U4MQ44TS.js +53 -0
  21. package/dist/chunk-VWJKRQZR.js +19 -0
  22. package/dist/chunk-XQ5O7IPO.js +128 -0
  23. package/dist/chunk-XZY2AWJI.js +81 -0
  24. package/dist/chunk-YVCR6FUH.js +82 -0
  25. package/dist/config/index.cjs +232 -128
  26. package/dist/config/index.d.cts +4 -6
  27. package/dist/config/index.d.ts +4 -6
  28. package/dist/config/index.js +26 -19
  29. package/dist/core-B6j6Fxse.d.cts +218 -0
  30. package/dist/core-B6j6Fxse.d.ts +218 -0
  31. package/dist/index.cjs +0 -76
  32. package/dist/index.d.cts +73 -20
  33. package/dist/index.d.ts +73 -20
  34. package/dist/index.js +0 -10
  35. package/dist/load-MNG3CLET.js +7 -0
  36. package/dist/next/index.cjs +567 -314
  37. package/dist/next/index.d.cts +9 -12
  38. package/dist/next/index.d.ts +9 -12
  39. package/dist/next/index.js +238 -211
  40. package/dist/node/loader.cjs +922 -0
  41. package/dist/node/loader.d.cts +5 -0
  42. package/dist/node/loader.d.ts +5 -0
  43. package/dist/node/loader.js +33 -0
  44. package/dist/plugins/json-schema.cjs +162 -0
  45. package/dist/plugins/json-schema.d.cts +24 -0
  46. package/dist/plugins/json-schema.d.ts +24 -0
  47. package/dist/plugins/json-schema.js +78 -0
  48. package/dist/{mdx-options-CAU273O3.js → preset-ZMP6U62C.js} +1 -1
  49. package/dist/runtime/next/async.cjs +715 -0
  50. package/dist/runtime/next/async.d.cts +21 -0
  51. package/dist/runtime/next/async.d.ts +21 -0
  52. package/dist/runtime/next/async.js +89 -0
  53. package/dist/runtime/next/index.cjs +136 -0
  54. package/dist/runtime/next/index.d.cts +33 -0
  55. package/dist/runtime/next/index.d.ts +33 -0
  56. package/dist/runtime/next/index.js +11 -0
  57. package/dist/runtime/vite/browser.cjs +107 -0
  58. package/dist/runtime/vite/browser.d.cts +59 -0
  59. package/dist/runtime/vite/browser.d.ts +59 -0
  60. package/dist/runtime/vite/browser.js +11 -0
  61. package/dist/runtime/vite/server.cjs +243 -0
  62. package/dist/runtime/vite/server.d.cts +30 -0
  63. package/dist/runtime/vite/server.d.ts +30 -0
  64. package/dist/runtime/vite/server.js +111 -0
  65. package/dist/types-AGzTfBmf.d.ts +45 -0
  66. package/dist/types-DKGMoay5.d.cts +45 -0
  67. package/dist/vite/index.cjs +1185 -0
  68. package/dist/vite/index.d.cts +45 -0
  69. package/dist/vite/index.d.ts +45 -0
  70. package/dist/vite/index.js +297 -0
  71. package/dist/webpack/index.cjs +957 -0
  72. package/dist/{loader-mdx.d.cts → webpack/index.d.cts} +3 -6
  73. package/dist/{loader-mdx.d.ts → webpack/index.d.ts} +3 -6
  74. package/dist/webpack/index.js +44 -0
  75. package/loader-mdx.cjs +1 -1
  76. package/package.json +86 -29
  77. package/bin.js +0 -5
  78. package/dist/chunk-2ZOW45YZ.js +0 -63
  79. package/dist/chunk-DRVUBK5B.js +0 -39
  80. package/dist/chunk-HFLDWPJA.js +0 -62
  81. package/dist/chunk-IOENRFUX.js +0 -112
  82. package/dist/chunk-MK7EXW7O.js +0 -75
  83. package/dist/define-BaW0PQDJ.d.cts +0 -201
  84. package/dist/define-BaW0PQDJ.d.ts +0 -201
  85. package/dist/loader-mdx.cjs +0 -527
  86. package/dist/loader-mdx.js +0 -162
  87. package/dist/runtime/async.cjs +0 -269
  88. package/dist/runtime/async.d.cts +0 -18
  89. package/dist/runtime/async.d.ts +0 -18
  90. package/dist/runtime/async.js +0 -73
  91. package/dist/types-BNrQHCj5.d.cts +0 -100
  92. package/dist/types-DEduCvIT.d.ts +0 -100
  93. package/dist/watcher-IAZDSTU7.js +0 -24
@@ -1,12 +1,9 @@
1
1
  import { LoaderContext } from 'webpack';
2
2
 
3
3
  interface Options {
4
- /**
5
- * @internal
6
- */
7
- _ctx: {
8
- configPath: string;
9
- };
4
+ configPath: string;
5
+ outDir: string;
6
+ isDev: boolean;
10
7
  }
11
8
  /**
12
9
  * Load MDX/markdown files
@@ -1,12 +1,9 @@
1
1
  import { LoaderContext } from 'webpack';
2
2
 
3
3
  interface Options {
4
- /**
5
- * @internal
6
- */
7
- _ctx: {
8
- configPath: string;
9
- };
4
+ configPath: string;
5
+ outDir: string;
6
+ isDev: boolean;
10
7
  }
11
8
  /**
12
9
  * Load MDX/markdown files
@@ -0,0 +1,44 @@
1
+ import {
2
+ toWebpack
3
+ } from "../chunk-YVCR6FUH.js";
4
+ import {
5
+ createMdxLoader
6
+ } from "../chunk-XQ5O7IPO.js";
7
+ import "../chunk-3J3WL7WN.js";
8
+ import "../chunk-K5ZLPEIQ.js";
9
+ import {
10
+ createCore,
11
+ dynamicConfig,
12
+ staticConfig
13
+ } from "../chunk-EELYB2XC.js";
14
+ import "../chunk-VWJKRQZR.js";
15
+
16
+ // src/webpack/index.ts
17
+ var instance;
18
+ async function loader(source, callback) {
19
+ const { isDev, outDir, configPath } = this.getOptions();
20
+ this.cacheable(true);
21
+ this.addDependency(configPath);
22
+ if (!instance) {
23
+ const core = createCore({
24
+ environment: "webpack",
25
+ outDir,
26
+ configPath
27
+ });
28
+ instance = toWebpack(
29
+ createMdxLoader(
30
+ isDev ? dynamicConfig({
31
+ core,
32
+ buildConfig: false
33
+ }) : staticConfig({
34
+ core,
35
+ buildConfig: false
36
+ })
37
+ )
38
+ );
39
+ }
40
+ await instance.call(this, source, callback);
41
+ }
42
+ export {
43
+ loader as default
44
+ };
package/loader-mdx.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  module.exports = function loader(code) {
2
2
  const callback = this.async();
3
3
 
4
- import('./dist/loader-mdx.js').then((mod) =>
4
+ import('./dist/webpack/index.js').then((mod) =>
5
5
  mod.default.call(this, code, callback),
6
6
  );
7
7
  };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "fumadocs-mdx",
3
- "version": "11.6.0",
3
+ "version": "13.0.1",
4
4
  "description": "The built-in source for Fumadocs",
5
5
  "keywords": [
6
6
  "NextJs",
7
7
  "Docs"
8
8
  ],
9
- "homepage": "https://fumadocs.vercel.app",
9
+ "homepage": "https://fumadocs.dev",
10
10
  "repository": "github:fuma-nama/fumadocs",
11
11
  "license": "MIT",
12
12
  "author": "Fuma Nama",
@@ -23,59 +23,116 @@
23
23
  "types": "./dist/next/index.d.ts",
24
24
  "require": "./dist/next/index.cjs"
25
25
  },
26
- "./runtime/async": {
27
- "import": "./dist/runtime/async.js",
28
- "types": "./dist/runtime/async.d.ts"
26
+ "./vite": {
27
+ "import": "./dist/vite/index.js",
28
+ "types": "./dist/vite/index.d.ts",
29
+ "require": "./dist/vite/index.cjs"
29
30
  },
30
31
  ".": {
31
32
  "import": "./dist/index.js",
32
- "types": "./dist/index.d.ts",
33
- "require": "./dist/index.cjs"
33
+ "types": "./dist/index.d.ts"
34
+ },
35
+ "./runtime/next": {
36
+ "import": "./dist/runtime/next/index.js",
37
+ "types": "./dist/runtime/next/index.d.ts"
38
+ },
39
+ "./runtime/async": {
40
+ "import": "./dist/runtime/next/async.js",
41
+ "types": "./dist/runtime/next/async.d.ts"
42
+ },
43
+ "./runtime/vite": {
44
+ "browser": "./dist/runtime/vite/browser.js",
45
+ "import": "./dist/runtime/vite/server.js",
46
+ "types": "./dist/runtime/vite/server.d.ts"
47
+ },
48
+ "./runtime/vite.server": {
49
+ "import": "./dist/runtime/vite/server.js",
50
+ "types": "./dist/runtime/vite/server.d.ts"
51
+ },
52
+ "./runtime/vite.browser": {
53
+ "import": "./dist/runtime/vite/browser.js",
54
+ "types": "./dist/runtime/vite/browser.d.ts"
55
+ },
56
+ "./node/loader": {
57
+ "import": "./dist/node/loader.js",
58
+ "types": "./dist/node/loader.d.ts"
59
+ },
60
+ "./bun": {
61
+ "import": "./dist/bun/index.js",
62
+ "types": "./dist/bun/index.d.ts"
63
+ },
64
+ "./plugins/*": {
65
+ "import": "./dist/plugins/*.js",
66
+ "types": "./dist/plugins/*.d.ts"
34
67
  }
35
68
  },
36
69
  "main": "./dist/index.js",
37
70
  "types": "./dist/index.d.ts",
38
- "bin": "./bin.js",
71
+ "bin": "./dist/bin.js",
39
72
  "files": [
40
73
  "dist/*",
41
- "loader-mdx.cjs",
42
- "bin.js"
74
+ "loader-mdx.cjs"
43
75
  ],
44
76
  "dependencies": {
45
- "@mdx-js/mdx": "^3.1.0",
77
+ "@mdx-js/mdx": "^3.1.1",
46
78
  "@standard-schema/spec": "^1.0.0",
47
79
  "chokidar": "^4.0.3",
48
- "cross-spawn": "^7.0.6",
49
- "esbuild": "^0.25.2",
50
- "estree-util-value-to-estree": "^3.3.3",
51
- "fast-glob": "^3.3.3",
52
- "gray-matter": "^4.0.3",
53
- "lru-cache": "^11.1.0",
80
+ "esbuild": "^0.25.11",
81
+ "estree-util-value-to-estree": "^3.4.1",
82
+ "js-yaml": "^4.1.0",
83
+ "lru-cache": "^11.2.2",
84
+ "mdast-util-to-markdown": "^2.1.2",
54
85
  "picocolors": "^1.1.1",
86
+ "picomatch": "^4.0.3",
87
+ "remark-mdx": "^3.1.1",
88
+ "tinyexec": "^1.0.1",
89
+ "tinyglobby": "^0.2.15",
90
+ "unified": "^11.0.5",
91
+ "unist-util-remove-position": "^5.0.0",
55
92
  "unist-util-visit": "^5.0.0",
56
- "zod": "^3.24.2"
93
+ "zod": "^4.1.12"
57
94
  },
58
95
  "devDependencies": {
59
- "@types/cross-spawn": "^6.0.6",
60
- "@types/mdast": "^4.0.3",
96
+ "@types/bun": "^1.3.0",
97
+ "@types/js-yaml": "^4.0.9",
98
+ "@types/mdast": "^4.0.4",
61
99
  "@types/mdx": "^2.0.13",
62
- "@types/react": "^19.1.0",
100
+ "@types/node": "^24.9.1",
101
+ "@types/picomatch": "^4.0.2",
102
+ "@types/react": "^19.2.2",
103
+ "mdast-util-directive": "^3.1.0",
63
104
  "mdast-util-mdx-jsx": "^3.2.0",
64
- "next": "^15.3.0",
65
- "unified": "^11.0.5",
105
+ "next": "16.0.0",
106
+ "react": "^19.2.0",
107
+ "remark": "^15.0.1",
108
+ "remark-directive": "^4.0.0",
109
+ "remark-stringify": "^11.0.0",
110
+ "rollup": "^4.52.5",
66
111
  "vfile": "^6.0.3",
67
- "webpack": "^5.99.5",
68
- "@fumadocs/mdx-remote": "1.3.0",
112
+ "vite": "^7.1.11",
113
+ "webpack": "^5.102.1",
114
+ "@fumadocs/mdx-remote": "1.4.3",
69
115
  "eslint-config-custom": "0.0.0",
70
- "fumadocs-core": "15.2.7",
116
+ "fumadocs-core": "16.0.3",
71
117
  "tsconfig": "0.0.0"
72
118
  },
73
119
  "peerDependencies": {
74
- "@fumadocs/mdx-remote": "^1.2.0",
75
- "fumadocs-core": "^14.0.0 || ^15.0.0",
76
- "next": "^15.3.0"
120
+ "@fumadocs/mdx-remote": "^1.4.0",
121
+ "fumadocs-core": "^15.0.0 || ^16.0.0",
122
+ "next": "^15.3.0 || ^16.0.0",
123
+ "react": "*",
124
+ "vite": "6.x.x || 7.x.x"
77
125
  },
78
126
  "peerDependenciesMeta": {
127
+ "react": {
128
+ "optional": true
129
+ },
130
+ "next": {
131
+ "optional": true
132
+ },
133
+ "vite": {
134
+ "optional": true
135
+ },
79
136
  "@fumadocs/mdx-remote": {
80
137
  "optional": true
81
138
  }
package/bin.js DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- import { postInstall } from './dist/next/index.js';
4
-
5
- void postInstall(process.argv[2]);
@@ -1,63 +0,0 @@
1
- // src/utils/schema.ts
2
- import { z } from "zod";
3
- import picocolors from "picocolors";
4
- var metaSchema = z.object({
5
- title: z.string().optional(),
6
- pages: z.array(z.string()).optional(),
7
- description: z.string().optional(),
8
- root: z.boolean().optional(),
9
- defaultOpen: z.boolean().optional(),
10
- icon: z.string().optional()
11
- });
12
- var frontmatterSchema = z.object({
13
- title: z.string(),
14
- description: z.string().optional(),
15
- icon: z.string().optional(),
16
- full: z.boolean().optional(),
17
- // Fumadocs OpenAPI generated
18
- _openapi: z.object({}).passthrough().optional()
19
- });
20
- var ValidationError = class extends Error {
21
- constructor(message, issues) {
22
- super(message);
23
- this.issues = issues;
24
- }
25
- print() {
26
- console.error(
27
- [
28
- `[MDX] ${this.message}:`,
29
- ...this.issues.map(
30
- (issue) => picocolors.redBright(
31
- `- ${picocolors.bold(issue.path?.join(".") ?? "*")}: ${issue.message}`
32
- )
33
- )
34
- ].join("\n")
35
- );
36
- }
37
- toString() {
38
- return `${this.message}:
39
- ${this.issues.map((issue) => ` ${issue.path}: ${issue.message}`).join("\n")}`;
40
- }
41
- };
42
- async function validate(schema, data, context, errorMessage) {
43
- if (typeof schema === "function" && !("~standard" in schema)) {
44
- schema = schema(context);
45
- }
46
- if ("~standard" in schema) {
47
- const result = await schema["~standard"].validate(
48
- data
49
- );
50
- if (result.issues) {
51
- throw new ValidationError(errorMessage, result.issues);
52
- }
53
- return result.value;
54
- }
55
- return data;
56
- }
57
-
58
- export {
59
- metaSchema,
60
- frontmatterSchema,
61
- ValidationError,
62
- validate
63
- };
@@ -1,39 +0,0 @@
1
- // src/config/build.ts
2
- function buildConfig(config) {
3
- const collections = /* @__PURE__ */ new Map();
4
- let globalConfig;
5
- for (const [k, v] of Object.entries(config)) {
6
- if (!v) {
7
- continue;
8
- }
9
- if (typeof v === "object" && "type" in v) {
10
- if (v.type === "docs") {
11
- collections.set(k, v);
12
- continue;
13
- }
14
- if (v.type === "doc" || v.type === "meta") {
15
- collections.set(k, v);
16
- continue;
17
- }
18
- }
19
- if (k === "default") {
20
- globalConfig = v;
21
- continue;
22
- }
23
- return [
24
- `Unknown export "${k}", you can only export collections from source configuration file.`,
25
- null
26
- ];
27
- }
28
- return [
29
- null,
30
- {
31
- global: globalConfig,
32
- collections
33
- }
34
- ];
35
- }
36
-
37
- export {
38
- buildConfig
39
- };
@@ -1,62 +0,0 @@
1
- import {
2
- buildConfig
3
- } from "./chunk-DRVUBK5B.js";
4
-
5
- // src/utils/config.ts
6
- import * as fs from "node:fs/promises";
7
- import * as path from "node:path";
8
- import { pathToFileURL } from "node:url";
9
- function findConfigFile() {
10
- return path.resolve("source.config.ts");
11
- }
12
- var cache = null;
13
- async function compileConfig(configPath, outDir) {
14
- const { build } = await import("esbuild");
15
- const transformed = await build({
16
- entryPoints: [{ in: configPath, out: "source.config" }],
17
- bundle: true,
18
- outdir: outDir,
19
- target: "node18",
20
- write: true,
21
- platform: "node",
22
- format: "esm",
23
- packages: "external",
24
- outExtension: {
25
- ".js": ".mjs"
26
- },
27
- allowOverwrite: true
28
- });
29
- if (transformed.errors.length > 0) {
30
- throw new Error("failed to compile configuration file");
31
- }
32
- }
33
- async function loadConfig(configPath, hash, build = false) {
34
- if (cache && cache.hash === hash) {
35
- return await cache.config;
36
- }
37
- if (build) await compileConfig(configPath, ".source");
38
- const url = pathToFileURL(path.resolve(".source/source.config.mjs"));
39
- const config = import(`${url.href}?hash=${hash}`).then((loaded) => {
40
- const [err, config2] = buildConfig(
41
- // every call to `loadConfig` will cause the previous cache to be ignored
42
- loaded
43
- );
44
- if (err !== null) throw new Error(err);
45
- return config2;
46
- });
47
- cache = { config, hash };
48
- return await config;
49
- }
50
- async function getConfigHash(configPath) {
51
- const stats = await fs.stat(configPath).catch(() => void 0);
52
- if (stats) {
53
- return stats.mtime.getTime().toString();
54
- }
55
- throw new Error("Cannot find config file");
56
- }
57
-
58
- export {
59
- findConfigFile,
60
- loadConfig,
61
- getConfigHash
62
- };
@@ -1,112 +0,0 @@
1
- // src/utils/mdx-options.ts
2
- import * as plugins from "fumadocs-core/mdx-plugins";
3
-
4
- // src/mdx-plugins/remark-exports.ts
5
- import { valueToEstree } from "estree-util-value-to-estree";
6
- function remarkMdxExport({ values }) {
7
- return (tree, vfile) => {
8
- for (const name of values) {
9
- if (!(name in vfile.data)) return;
10
- tree.children.unshift(getMdastExport(name, vfile.data[name]));
11
- }
12
- };
13
- }
14
- function getMdastExport(name, value) {
15
- return {
16
- type: "mdxjsEsm",
17
- value: "",
18
- data: {
19
- estree: {
20
- type: "Program",
21
- sourceType: "module",
22
- body: [
23
- {
24
- type: "ExportNamedDeclaration",
25
- specifiers: [],
26
- source: null,
27
- declaration: {
28
- type: "VariableDeclaration",
29
- kind: "let",
30
- declarations: [
31
- {
32
- type: "VariableDeclarator",
33
- id: {
34
- type: "Identifier",
35
- name
36
- },
37
- init: valueToEstree(value)
38
- }
39
- ]
40
- }
41
- }
42
- ]
43
- }
44
- }
45
- };
46
- }
47
-
48
- // src/utils/mdx-options.ts
49
- function pluginOption(def, options = []) {
50
- const list = def(Array.isArray(options) ? options : []).filter(
51
- Boolean
52
- );
53
- if (typeof options === "function") {
54
- return options(list);
55
- }
56
- return list;
57
- }
58
- function getDefaultMDXOptions({
59
- valueToExport = [],
60
- rehypeCodeOptions,
61
- remarkImageOptions,
62
- remarkHeadingOptions,
63
- remarkStructureOptions,
64
- remarkCodeTabOptions,
65
- ...mdxOptions
66
- }) {
67
- const mdxExports = [
68
- "structuredData",
69
- "frontmatter",
70
- "lastModified",
71
- ...valueToExport
72
- ];
73
- const remarkPlugins = pluginOption(
74
- (v) => [
75
- plugins.remarkGfm,
76
- [
77
- plugins.remarkHeading,
78
- {
79
- generateToc: false,
80
- ...remarkHeadingOptions
81
- }
82
- ],
83
- remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
84
- // Fumadocs 14 compatibility
85
- "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && plugins.remarkCodeTab,
86
- ...v,
87
- remarkStructureOptions !== false && [
88
- plugins.remarkStructure,
89
- remarkStructureOptions
90
- ],
91
- [remarkMdxExport, { values: mdxExports }]
92
- ],
93
- mdxOptions.remarkPlugins
94
- );
95
- const rehypePlugins = pluginOption(
96
- (v) => [
97
- rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
98
- ...v,
99
- [plugins.rehypeToc]
100
- ],
101
- mdxOptions.rehypePlugins
102
- );
103
- return {
104
- ...mdxOptions,
105
- remarkPlugins,
106
- rehypePlugins
107
- };
108
- }
109
-
110
- export {
111
- getDefaultMDXOptions
112
- };
@@ -1,75 +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 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(
17
- tree,
18
- ["mdxJsxFlowElement", "mdxJsxTextElement"],
19
- (node, _, parent) => {
20
- let specifier;
21
- const params = {};
22
- if ((node.type === "mdxJsxFlowElement" || node.type === "mdxJsxTextElement") && node.name === TagName) {
23
- const value = flattenNode(node);
24
- if (value.length > 0) {
25
- for (const attr of node.attributes) {
26
- if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
27
- params[attr.name] = attr.value;
28
- }
29
- }
30
- specifier = value;
31
- }
32
- }
33
- if (!specifier) return;
34
- const targetPath = path.resolve(
35
- "cwd" in params ? process.cwd() : path.dirname(file),
36
- specifier
37
- );
38
- const asCode = params.lang || !specifier.endsWith(".md") && !specifier.endsWith(".mdx");
39
- queue.push(
40
- fs.readFile(targetPath).then(async (content) => {
41
- compiler?.addDependency(targetPath);
42
- if (asCode) {
43
- const lang = params.lang ?? path.extname(specifier).slice(1);
44
- Object.assign(node, {
45
- type: "code",
46
- lang,
47
- meta: params.meta,
48
- value: content.toString(),
49
- data: {}
50
- });
51
- return;
52
- }
53
- const parsed = processor.parse(matter(content).content);
54
- await update(parsed, targetPath, processor, compiler);
55
- Object.assign(
56
- parent && parent.type === "paragraph" ? parent : node,
57
- parsed
58
- );
59
- }).catch((e) => {
60
- console.warn(`failed to read file: ${targetPath}`, e);
61
- })
62
- );
63
- return "skip";
64
- }
65
- );
66
- await Promise.all(queue);
67
- }
68
- return async (tree, file) => {
69
- await update(tree, file.path, this, file.data._compiler);
70
- };
71
- }
72
-
73
- export {
74
- remarkInclude
75
- };