fumadocs-mdx 11.6.8 → 11.6.10

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.
@@ -62,6 +62,7 @@ function getDefaultMDXOptions({
62
62
  remarkHeadingOptions,
63
63
  remarkStructureOptions,
64
64
  remarkCodeTabOptions,
65
+ remarkNpmOptions,
65
66
  ...mdxOptions
66
67
  }) {
67
68
  const mdxExports = [
@@ -81,11 +82,11 @@ function getDefaultMDXOptions({
81
82
  }
82
83
  ],
83
84
  remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
84
- // Fumadocs 14 compatibility
85
85
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
86
86
  plugins.remarkCodeTab,
87
87
  remarkCodeTabOptions
88
88
  ],
89
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
89
90
  ...v,
90
91
  remarkStructureOptions !== false && [
91
92
  plugins.remarkStructure,
@@ -109,7 +110,16 @@ function getDefaultMDXOptions({
109
110
  rehypePlugins
110
111
  };
111
112
  }
113
+ async function loadDefaultOptions(config) {
114
+ const input = config.global?.mdxOptions;
115
+ config._mdx_loader ??= {};
116
+ const mdxLoader = config._mdx_loader;
117
+ if (!mdxLoader.cachedOptions) {
118
+ mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
119
+ }
120
+ return mdxLoader.cachedOptions;
121
+ }
112
122
 
113
123
  export {
114
- getDefaultMDXOptions
124
+ loadDefaultOptions
115
125
  };
@@ -0,0 +1,49 @@
1
+ import {
2
+ remarkInclude
3
+ } from "./chunk-AVMO2SRO.js";
4
+
5
+ // src/utils/build-mdx.ts
6
+ import { createProcessor } from "@mdx-js/mdx";
7
+ var cache = /* @__PURE__ */ new Map();
8
+ async function buildMDX(cacheKey, source, options) {
9
+ const { filePath, frontmatter, data, ...rest } = options;
10
+ let format = options.format;
11
+ if (!format && filePath) {
12
+ format = filePath.endsWith(".mdx") ? "mdx" : "md";
13
+ }
14
+ format ??= "mdx";
15
+ const key = `${cacheKey}:${format}`;
16
+ let cached = cache.get(key);
17
+ if (!cached) {
18
+ cached = createProcessor({
19
+ outputFormat: "program",
20
+ ...rest,
21
+ remarkPlugins: [remarkInclude, ...rest.remarkPlugins ?? []],
22
+ format
23
+ });
24
+ cache.set(key, cached);
25
+ }
26
+ return cached.process({
27
+ value: source,
28
+ path: filePath,
29
+ data: {
30
+ ...data,
31
+ frontmatter,
32
+ _compiler: options._compiler
33
+ }
34
+ });
35
+ }
36
+
37
+ // src/utils/count-lines.ts
38
+ function countLines(s) {
39
+ let num = 0;
40
+ for (const c of s) {
41
+ if (c === "\n") num++;
42
+ }
43
+ return num;
44
+ }
45
+
46
+ export {
47
+ buildMDX,
48
+ countLines
49
+ };
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  fumaMatter
3
- } from "./chunk-MXACIHNJ.js";
3
+ } from "./chunk-KVWX6THC.js";
4
4
 
5
5
  // src/mdx-plugins/remark-include.ts
6
6
  import { visit } from "unist-util-visit";
@@ -0,0 +1,19 @@
1
+ // src/utils/fuma-matter.ts
2
+ import { load } from "js-yaml";
3
+ var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
4
+ function fumaMatter(input) {
5
+ const output = { matter: "", data: {}, content: input };
6
+ const match = regex.exec(input);
7
+ if (!match) {
8
+ return output;
9
+ }
10
+ output.matter = match[1];
11
+ output.content = input.slice(match[0].length);
12
+ const loaded = load(output.matter);
13
+ output.data = loaded ?? {};
14
+ return output;
15
+ }
16
+
17
+ export {
18
+ fumaMatter
19
+ };
@@ -34,7 +34,7 @@ __export(config_exports, {
34
34
  defineConfig: () => defineConfig,
35
35
  defineDocs: () => defineDocs,
36
36
  frontmatterSchema: () => frontmatterSchema,
37
- getDefaultMDXOptions: () => getDefaultMDXOptions,
37
+ loadDefaultOptions: () => loadDefaultOptions,
38
38
  metaSchema: () => metaSchema,
39
39
  remarkInclude: () => remarkInclude
40
40
  });
@@ -161,6 +161,7 @@ function getDefaultMDXOptions({
161
161
  remarkHeadingOptions,
162
162
  remarkStructureOptions,
163
163
  remarkCodeTabOptions,
164
+ remarkNpmOptions,
164
165
  ...mdxOptions
165
166
  }) {
166
167
  const mdxExports = [
@@ -180,11 +181,11 @@ function getDefaultMDXOptions({
180
181
  }
181
182
  ],
182
183
  remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
183
- // Fumadocs 14 compatibility
184
184
  "remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [
185
185
  plugins.remarkCodeTab,
186
186
  remarkCodeTabOptions
187
187
  ],
188
+ "remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
188
189
  ...v,
189
190
  remarkStructureOptions !== false && [
190
191
  plugins.remarkStructure,
@@ -208,6 +209,15 @@ function getDefaultMDXOptions({
208
209
  rehypePlugins
209
210
  };
210
211
  }
212
+ async function loadDefaultOptions(config) {
213
+ const input = config.global?.mdxOptions;
214
+ config._mdx_loader ??= {};
215
+ const mdxLoader = config._mdx_loader;
216
+ if (!mdxLoader.cachedOptions) {
217
+ mdxLoader.cachedOptions = typeof input === "function" ? getDefaultMDXOptions(await input()) : getDefaultMDXOptions(input ?? {});
218
+ }
219
+ return mdxLoader.cachedOptions;
220
+ }
211
221
 
212
222
  // src/mdx-plugins/remark-include.ts
213
223
  var import_unist_util_visit = require("unist-util-visit");
@@ -215,37 +225,16 @@ var path = __toESM(require("path"), 1);
215
225
  var fs = __toESM(require("fs/promises"), 1);
216
226
 
217
227
  // src/utils/fuma-matter.ts
218
- var import_lru_cache = require("lru-cache");
219
228
  var import_js_yaml = require("js-yaml");
220
- var cache = new import_lru_cache.LRUCache({
221
- max: 200
222
- });
229
+ var regex = /^---\r?\n(.+?)\r?\n---\r?\n/s;
223
230
  function fumaMatter(input) {
224
- if (input === "") {
225
- return { data: {}, content: input, matter: "" };
226
- }
227
- const cached = cache.get(input);
228
- if (cached) return cached;
229
- const result = parseMatter(input);
230
- cache.set(input, result);
231
- return structuredClone(result);
232
- }
233
- var delimiter = "---";
234
- function parseMatter(str) {
235
- const output = { matter: "", data: {}, content: str };
236
- const open = delimiter + "\n";
237
- const close = "\n" + delimiter;
238
- if (!str.startsWith(open)) {
231
+ const output = { matter: "", data: {}, content: input };
232
+ const match = regex.exec(input);
233
+ if (!match) {
239
234
  return output;
240
235
  }
241
- str = str.slice(open.length);
242
- const len = str.length;
243
- let closeIdx = str.indexOf(close);
244
- if (closeIdx === -1) {
245
- closeIdx = len;
246
- }
247
- output.matter = str.slice(0, closeIdx);
248
- output.content = str.slice(closeIdx + close.length);
236
+ output.matter = match[1];
237
+ output.content = input.slice(match[0].length);
249
238
  const loaded = (0, import_js_yaml.load)(output.matter);
250
239
  output.data = loaded ?? {};
251
240
  return output;
@@ -327,7 +316,7 @@ ${e instanceof Error ? e.message : String(e)}`
327
316
  defineConfig,
328
317
  defineDocs,
329
318
  frontmatterSchema,
330
- getDefaultMDXOptions,
319
+ loadDefaultOptions,
331
320
  metaSchema,
332
321
  remarkInclude
333
322
  });
@@ -1,13 +1,14 @@
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-uoePrCQ_.cjs';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, D as DefaultMDXOptions, c as DocCollection, d as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, e as defineCollections, h as defineConfig, g as defineDocs, f as frontmatterSchema, l as loadDefaultOptions, m as metaSchema } from '../types-DvTNxAvo.cjs';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
- import '@mdx-js/mdx';
5
4
  import 'mdx/types';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import 'fumadocs-core/server';
7
+ import '@mdx-js/mdx';
8
8
  import 'react';
9
9
  import 'zod';
10
10
  import '@standard-schema/spec';
11
+ import '@fumadocs/mdx-remote';
11
12
 
12
13
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
13
14
 
@@ -1,13 +1,14 @@
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-uoePrCQ_.js';
1
+ export { a as BaseCollection, B as BaseCollectionEntry, C as CollectionSchema, D as DefaultMDXOptions, c as DocCollection, d as DocsCollection, F as FileInfo, G as GlobalConfig, M as MarkdownProps, b as MetaCollection, e as defineCollections, h as defineConfig, g as defineDocs, f as frontmatterSchema, l as loadDefaultOptions, m as metaSchema } from '../types-DvTNxAvo.js';
2
2
  import { Processor, Transformer } from 'unified';
3
3
  import { Root } from 'mdast';
4
- import '@mdx-js/mdx';
5
4
  import 'mdx/types';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import 'fumadocs-core/server';
7
+ import '@mdx-js/mdx';
8
8
  import 'react';
9
9
  import 'zod';
10
10
  import '@standard-schema/spec';
11
+ import '@fumadocs/mdx-remote';
11
12
 
12
13
  declare function remarkInclude(this: Processor): Transformer<Root, Root>;
13
14
 
@@ -3,12 +3,12 @@ import {
3
3
  metaSchema
4
4
  } from "../chunk-OTM6WYMS.js";
5
5
  import {
6
- remarkInclude
7
- } from "../chunk-KTLWF7GN.js";
8
- import "../chunk-MXACIHNJ.js";
6
+ loadDefaultOptions
7
+ } from "../chunk-64MMPGML.js";
9
8
  import {
10
- getDefaultMDXOptions
11
- } from "../chunk-VC3Y6FLZ.js";
9
+ remarkInclude
10
+ } from "../chunk-AVMO2SRO.js";
11
+ import "../chunk-KVWX6THC.js";
12
12
 
13
13
  // src/config/define.ts
14
14
  function defineCollections(options) {
@@ -51,7 +51,7 @@ export {
51
51
  defineConfig,
52
52
  defineDocs,
53
53
  frontmatterSchema,
54
- getDefaultMDXOptions,
54
+ loadDefaultOptions,
55
55
  metaSchema,
56
56
  remarkInclude
57
57
  };
package/dist/index.d.cts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-uoePrCQ_.cjs';
3
- import { R as Runtime } from './types-BsJd_P5O.cjs';
4
- import '@mdx-js/mdx';
2
+ import { B as BaseCollectionEntry } from './types-DvTNxAvo.cjs';
3
+ import { R as Runtime } from './types-ZwLebhOl.cjs';
5
4
  import 'mdx/types';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import 'fumadocs-core/server';
7
+ import '@mdx-js/mdx';
8
8
  import 'unified';
9
9
  import 'react';
10
10
  import 'zod';
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { PageData, MetaData, Source, VirtualFile } from 'fumadocs-core/source';
2
- import { B as BaseCollectionEntry } from './define-uoePrCQ_.js';
3
- import { R as Runtime } from './types-BYJBKH4G.js';
4
- import '@mdx-js/mdx';
2
+ import { B as BaseCollectionEntry } from './types-DvTNxAvo.js';
3
+ import { R as Runtime } from './types-Dk7DhSKZ.js';
5
4
  import 'mdx/types';
6
5
  import 'fumadocs-core/mdx-plugins';
7
6
  import 'fumadocs-core/server';
7
+ import '@mdx-js/mdx';
8
8
  import 'unified';
9
9
  import 'react';
10
10
  import 'zod';