fumadocs-mdx 15.4.8 → 15.4.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.
- package/dist/{adapter-CUvGnUav.js → adapter-BUIa-1SI.js} +1 -1
- package/dist/{build-H2VN-Hpm.js → build-DXxE3Ml4.js} +1 -1
- package/dist/{build-default-CSiWktEh.js → build-default-C-XpLSiW.js} +23 -5
- package/dist/bun/index.d.ts +1 -1
- package/dist/bun/index.js +3 -3
- package/dist/config/index.d.ts +24 -3
- package/dist/config/index.js +2 -1
- package/dist/{core-6H7qqwEM.d.ts → core-w3CkO8cV.d.ts} +4 -4
- package/dist/{eval-DGn_JC7j.js → eval-Cnxpyc4j.js} +4 -1
- package/dist/{index-CIxuOQ_6.d.ts → index-C8JoWO0_.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/{load-from-file-Cp200K3r.js → load-from-file-DGFWQ0eg.js} +4 -1
- package/dist/macro/index.d.ts +1 -1
- package/dist/{mdx-D0Qtc99b.js → mdx-Cmy8JCce.js} +1 -1
- package/dist/next/index.d.ts +1 -1
- package/dist/next/index.js +1 -1
- package/dist/node/_loader.js +3 -3
- package/dist/node/index.d.ts +1 -1
- package/dist/node/loader.js +2 -2
- package/dist/plugins/index-file.d.ts +1 -1
- package/dist/plugins/index-file.js +1 -2
- package/dist/plugins/json-schema.d.ts +1 -1
- package/dist/plugins/last-modified.d.ts +1 -1
- package/dist/preset-NZprPlqc.js +59 -0
- package/dist/rolldown/index.d.ts +1 -1
- package/dist/rolldown/index.js +3 -3
- package/dist/runtime/browser.d.ts +3 -2
- package/dist/runtime/dynamic.d.ts +2 -2
- package/dist/runtime/dynamic.js +1 -1
- package/dist/runtime/macro.d.ts +2 -1
- package/dist/runtime/server.d.ts +4 -3
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +3 -3
- package/dist/webpack/macro.d.ts +1 -1
- package/dist/webpack/mdx.d.ts +1 -1
- package/dist/webpack/mdx.js +3 -3
- package/dist/webpack/meta.d.ts +1 -1
- package/dist/webpack/meta.js +2 -2
- package/dist/{webpack-BgaNFImR.js → webpack-BozYCamo.js} +1 -1
- package/package.json +17 -17
- package/dist/index-DosG5f9I.d.ts +0 -28
- package/dist/remark-include-WlmaWKPS.js +0 -318
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as buildConfig, n as ValidationError } from "./core-DV3f7rXs.js";
|
|
2
|
-
import { t as loadConfig } from "./load-from-file-
|
|
2
|
+
import { t as loadConfig } from "./load-from-file-DGFWQ0eg.js";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import fs from "node:fs/promises";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
@@ -6,7 +6,7 @@ async function buildMDX(core, collection, options) {
|
|
|
6
6
|
const { buildSatteriMDX } = await import("./build-satteri-DUjpwpvb.js");
|
|
7
7
|
return buildSatteriMDX(core, collection, options);
|
|
8
8
|
}
|
|
9
|
-
const { buildJSMDX } = await import("./build-default-
|
|
9
|
+
const { buildJSMDX } = await import("./build-default-C-XpLSiW.js");
|
|
10
10
|
return buildJSMDX(core, collection, options);
|
|
11
11
|
}
|
|
12
12
|
//#endregion
|
|
@@ -1,10 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as applyMdxPreset } from "./preset-NZprPlqc.js";
|
|
2
2
|
import { t as resolveLastModified } from "./last-modified-BkZYFKSh.js";
|
|
3
|
-
import {
|
|
3
|
+
import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
|
|
4
4
|
import { createProcessor } from "@mdx-js/mdx";
|
|
5
|
+
import { VFile } from "vfile";
|
|
5
6
|
import { valueToEstree } from "estree-util-value-to-estree";
|
|
6
7
|
import { removePosition } from "unist-util-remove-position";
|
|
7
8
|
import { remarkLLMs } from "fumadocs-core/mdx-plugins/remark-llms";
|
|
9
|
+
//#region src/loaders/mdx/mdast-utils.ts
|
|
10
|
+
function flattenNode(node) {
|
|
11
|
+
if ("children" in node) return node.children.map((child) => flattenNode(child)).join("");
|
|
12
|
+
if ("value" in node) return node.value;
|
|
13
|
+
return "";
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Visit a tree in document order, returning `skip` skips the children of a node and `false` stops the walk.
|
|
17
|
+
*/
|
|
18
|
+
function walk(node, visitor, index, parent) {
|
|
19
|
+
const result = visitor(node, index, parent);
|
|
20
|
+
if (result === false) return false;
|
|
21
|
+
if (result !== "skip" && node.children) {
|
|
22
|
+
for (let i = 0; i < node.children.length; i++) if (!walk(node.children[i], visitor, i, node)) return false;
|
|
23
|
+
}
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
//#endregion
|
|
8
27
|
//#region src/loaders/mdx/remark-postprocess.ts
|
|
9
28
|
/**
|
|
10
29
|
* - collect references
|
|
@@ -109,7 +128,7 @@ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _co
|
|
|
109
128
|
development: isDevelopment,
|
|
110
129
|
...mdxOptions,
|
|
111
130
|
remarkPlugins: [
|
|
112
|
-
remarkInclude,
|
|
131
|
+
[remarkInclude, { getProcessor }],
|
|
113
132
|
...mdxOptions.remarkPlugins ?? [],
|
|
114
133
|
[remarkPostprocess, postprocessOptions]
|
|
115
134
|
],
|
|
@@ -125,8 +144,7 @@ async function buildJSMDX(core, collection, { filePath, frontmatter, source, _co
|
|
|
125
144
|
cwd: collection?.cwd,
|
|
126
145
|
data: {
|
|
127
146
|
frontmatter,
|
|
128
|
-
_compiler
|
|
129
|
-
_getProcessor: getProcessor
|
|
147
|
+
_compiler
|
|
130
148
|
}
|
|
131
149
|
});
|
|
132
150
|
if (collection) vfile = await core.transformVFile({
|
package/dist/bun/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CoreOptions } from "../core-
|
|
1
|
+
import { r as CoreOptions } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { n as ResolvedMacroOptions, t as MacroPluginOption } from "../options-aB6xV-d7.js";
|
|
3
3
|
import { BunPlugin } from "bun";
|
|
4
4
|
//#region src/bun/index.d.ts
|
package/dist/bun/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
2
|
import { i as buildConfig, t as createCore } from "../core-DV3f7rXs.js";
|
|
3
3
|
import { r as slash } from "../codegen-DfCJFqO-.js";
|
|
4
|
-
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-
|
|
4
|
+
import { a as createIntegratedConfigLoader, t as toBun } from "../adapter-BUIa-1SI.js";
|
|
5
5
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
6
6
|
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
7
7
|
import { r as resolveMacroOptions } from "../options-BNnYUjkM.js";
|
|
@@ -44,7 +44,7 @@ function createMdxPlugin(options = {}) {
|
|
|
44
44
|
await core.init({ config: buildConfig(configExports, process.cwd()) });
|
|
45
45
|
if (macroOptions) {
|
|
46
46
|
const root = process.cwd();
|
|
47
|
-
const { MacroCollector } = await import("../eval-
|
|
47
|
+
const { MacroCollector } = await import("../eval-Cnxpyc4j.js").then((n) => n.r);
|
|
48
48
|
const pendingEvals = /* @__PURE__ */ new Map();
|
|
49
49
|
core.macro = new MacroCollector({
|
|
50
50
|
root,
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
-
import { C as DocsCollection, D as defineCollections, E as SatteriPresetOptions, F as DefaultMDXOptions, I as MDXPresetOptions, L as applyMdxPreset, O as defineConfig, P as PostprocessOptions, S as DocCollectionSatteri, T as MetaCollection, _ as BaseCollection, b as DocCollectionBase, g as AnyCollection, k as defineDocs, v as CollectionSchema, w as GlobalConfig, x as DocCollectionMdx, y as DocCollection } from "../core-
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
import { C as DocsCollection, D as defineCollections, E as SatteriPresetOptions, F as DefaultMDXOptions, I as MDXPresetOptions, L as applyMdxPreset, O as defineConfig, P as PostprocessOptions, S as DocCollectionSatteri, T as MetaCollection, _ as BaseCollection, b as DocCollectionBase, g as AnyCollection, k as defineDocs, v as CollectionSchema, w as GlobalConfig, x as DocCollectionMdx, y as DocCollection } from "../core-w3CkO8cV.js";
|
|
2
|
+
import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
|
|
3
|
+
//#region src/config/index.d.ts
|
|
4
|
+
/** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
5
|
+
export declare const frontmatterSchema: import("zod").ZodObject<{
|
|
6
|
+
title: import("zod").ZodString;
|
|
7
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
8
|
+
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
9
|
+
full: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
10
|
+
_openapi: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodCustom<import("fumadocs-core/source/schema")._JSONType, import("fumadocs-core/source/schema")._JSONType>>>;
|
|
11
|
+
}, import("zod/v4/core").$strip>;
|
|
12
|
+
/** @deprecated import from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
13
|
+
export declare const metaSchema: import("zod").ZodObject<{
|
|
14
|
+
title: import("zod").ZodOptional<import("zod").ZodString>;
|
|
15
|
+
pages: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
16
|
+
pagesIndex: import("zod").ZodOptional<import("zod").ZodString>;
|
|
17
|
+
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
18
|
+
root: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodString]>>;
|
|
19
|
+
defaultOpen: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
20
|
+
collapsible: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
21
|
+
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
22
|
+
}, import("zod/v4/core").$strip>;
|
|
23
|
+
//#endregion
|
|
24
|
+
export { AnyCollection, BaseCollection, CollectionSchema, DefaultMDXOptions, DocCollection, DocCollectionBase, DocCollectionMdx, DocCollectionSatteri, DocsCollection, GlobalConfig, MDXPresetOptions, MetaCollection, type PostprocessOptions, type SatteriPresetOptions, applyMdxPreset, defineCollections, defineConfig, defineDocs, remarkInclude };
|
package/dist/config/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { n as defineConfig, r as defineDocs, t as defineCollections } from "../define-BW5lveuc.js";
|
|
2
|
-
import {
|
|
2
|
+
import { t as applyMdxPreset } from "../preset-NZprPlqc.js";
|
|
3
3
|
import { metaSchema as metaSchema$1, pageSchema } from "fumadocs-core/source/schema";
|
|
4
|
+
import { remarkInclude } from "fumadocs-core/mdx-plugins/remark-include";
|
|
4
5
|
//#region src/config/index.ts
|
|
5
6
|
/** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
6
7
|
const frontmatterSchema = pageSchema;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
|
|
2
|
-
import { Pluggable, Transformer } from "unified";
|
|
3
|
-
import * as Plugins from "fumadocs-core/mdx-plugins";
|
|
4
|
-
import { LLMsOptions, StructuredData } from "fumadocs-core/mdx-plugins";
|
|
5
|
-
import { VFile } from "vfile";
|
|
6
2
|
import { FC } from "react";
|
|
7
3
|
import { ProcessorOptions } from "@mdx-js/mdx";
|
|
4
|
+
import { VFile } from "vfile";
|
|
8
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
6
|
+
import { Pluggable } from "unified";
|
|
7
|
+
import * as Plugins from "fumadocs-core/mdx-plugins";
|
|
8
|
+
import { LLMsOptions, StructuredData } from "fumadocs-core/mdx-plugins";
|
|
9
9
|
import { Root } from "mdast";
|
|
10
10
|
import { SatteriPresetOptions, SatteriPresetOptions as SatteriPresetOptions$1 } from "@fumadocs/satteri/preset";
|
|
11
11
|
import { TOCItemType } from "fumadocs-core/toc";
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { N as ExtractedReference, a as EmitOptions, c as PluginContext, d as TransformOptions, i as EmitEntry, j as CompiledMDXProperties, l as PluginOption, n as Core, o as EmitOutput, r as CoreOptions, s as Plugin, t as CompilationContext, u as ServerContext } from "./core-
|
|
1
|
+
import { N as ExtractedReference, a as EmitOptions, c as PluginContext, d as TransformOptions, i as EmitEntry, j as CompiledMDXProperties, l as PluginOption, n as Core, o as EmitOutput, r as CoreOptions, s as Plugin, t as CompilationContext, u as ServerContext } from "./core-w3CkO8cV.js";
|
|
2
2
|
export type { CompilationContext, CompiledMDXProperties, Core, CoreOptions, EmitEntry, EmitOptions, EmitOutput, ExtractedReference, Plugin, PluginContext, PluginOption, ServerContext, TransformOptions };
|
|
@@ -46,7 +46,10 @@ async function loadConfig(core, build = false) {
|
|
|
46
46
|
const url = pathToFileURL(core.getCompiledConfigPath());
|
|
47
47
|
url.searchParams.set("hash", Date.now().toString());
|
|
48
48
|
return {
|
|
49
|
-
config: buildConfig(await import(
|
|
49
|
+
config: buildConfig(await import(
|
|
50
|
+
/* turbopackIgnore: true */
|
|
51
|
+
url.href
|
|
52
|
+
), process.cwd()),
|
|
50
53
|
fromFile: true
|
|
51
54
|
};
|
|
52
55
|
}
|
package/dist/macro/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as SatteriOptionsInput, N as ExtractedReference, P as PostprocessOptions, h as BuildEnvironment, v as CollectionSchema } from "../core-
|
|
1
|
+
import { A as SatteriOptionsInput, N as ExtractedReference, P as PostprocessOptions, h as BuildEnvironment, v as CollectionSchema } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { MacroAsyncDocCollection, MacroAsyncDocsCollection, MacroDocCollection, MacroDocsCollection, MacroMetaCollection } from "../runtime/macro.js";
|
|
3
3
|
import { metaSchema, pageSchema } from "fumadocs-core/source/schema";
|
|
4
4
|
import { MetaData, PageData } from "fumadocs-core/source";
|
|
@@ -60,7 +60,7 @@ function createMdxLoader({ getCore }) {
|
|
|
60
60
|
source: value
|
|
61
61
|
}, matter.data);
|
|
62
62
|
if (only === "frontmatter") return { code: `export const frontmatter = ${JSON.stringify(matter.data)}` };
|
|
63
|
-
const { buildMDX } = await import("./build-
|
|
63
|
+
const { buildMDX } = await import("./build-DXxE3Ml4.js").then((n) => n.n);
|
|
64
64
|
const compiled = await buildMDX(core, docCollection, {
|
|
65
65
|
isDevelopment,
|
|
66
66
|
source: "\n".repeat(countLines(matter.matter)) + matter.content,
|
package/dist/next/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { p as IndexFilePluginOptions, r as CoreOptions } from "../core-
|
|
1
|
+
import { p as IndexFilePluginOptions, r as CoreOptions } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { t as MacroPluginOption } from "../options-aB6xV-d7.js";
|
|
3
3
|
import { NextConfig } from "next";
|
|
4
4
|
//#region src/next/index.d.ts
|
package/dist/next/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as createCore } from "../core-DV3f7rXs.js";
|
|
2
|
-
import { t as loadConfig } from "../load-from-file-
|
|
2
|
+
import { t as loadConfig } from "../load-from-file-DGFWQ0eg.js";
|
|
3
3
|
import { i as metaLoaderQueryGlob, n as metaLoaderFileGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
4
4
|
import { n as createMacroMatcher, r as resolveMacroOptions } from "../options-BNnYUjkM.js";
|
|
5
5
|
import { t as indexFile } from "../index-file-C9-jDz59.js";
|
package/dist/node/_loader.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
2
|
import { t as createCore } from "../core-DV3f7rXs.js";
|
|
3
3
|
import { r as slash } from "../codegen-DfCJFqO-.js";
|
|
4
|
-
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-
|
|
4
|
+
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-BUIa-1SI.js";
|
|
5
5
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
6
6
|
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
7
7
|
import { n as createMacroMatcher, r as resolveMacroOptions } from "../options-BNnYUjkM.js";
|
|
8
|
-
import { n as createNodeEvaluator, t as MacroCollector } from "../eval-
|
|
8
|
+
import { n as createNodeEvaluator, t as MacroCollector } from "../eval-Cnxpyc4j.js";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
11
|
//#region src/node/_loader.ts
|
package/dist/node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as CoreOptions } from "../core-
|
|
1
|
+
import { r as CoreOptions } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { t as MacroPluginOption } from "../options-aB6xV-d7.js";
|
|
3
3
|
//#region src/node/index.d.ts
|
|
4
4
|
export interface NodeLoaderOptions extends Pick<CoreOptions, 'configPath' | 'outDir' | 'plugins'> {
|
package/dist/node/loader.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
2
|
import { t as createCore } from "../core-DV3f7rXs.js";
|
|
3
|
-
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-
|
|
3
|
+
import { n as toNode, o as createStandaloneConfigLoader } from "../adapter-BUIa-1SI.js";
|
|
4
4
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
5
5
|
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
6
6
|
//#region src/node/loader.ts
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { f as IndexFilePlugin, m as indexFile, p as IndexFilePluginOptions } from "../core-
|
|
1
|
+
import { f as IndexFilePlugin, m as indexFile, p as IndexFilePluginOptions } from "../core-w3CkO8cV.js";
|
|
2
2
|
export { IndexFilePlugin, IndexFilePluginOptions, indexFile as default };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { indexFile as default };
|
|
1
|
+
export { t as default } from "../index-file-C9-jDz59.js";
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region src/config/preset.ts
|
|
2
|
+
function pluginOption(def, options = []) {
|
|
3
|
+
const list = def(Array.isArray(options) ? options : []).filter(Boolean);
|
|
4
|
+
if (typeof options === "function") return options(list);
|
|
5
|
+
return list;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* apply MDX processor presets
|
|
9
|
+
*/
|
|
10
|
+
function applyMdxPreset(options = {}) {
|
|
11
|
+
return async (environment = "bundler") => {
|
|
12
|
+
if (options.preset === "minimal") return options;
|
|
13
|
+
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
14
|
+
const { valueToExport = [], rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, ...mdxOptions } = options;
|
|
15
|
+
const remarkPlugins = pluginOption((v) => [
|
|
16
|
+
plugins.remarkGfm,
|
|
17
|
+
[plugins.remarkHeading, {
|
|
18
|
+
generateToc: false,
|
|
19
|
+
...remarkHeadingOptions
|
|
20
|
+
}],
|
|
21
|
+
remarkImageOptions !== false && [plugins.remarkImage, {
|
|
22
|
+
...remarkImageOptions,
|
|
23
|
+
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
24
|
+
}],
|
|
25
|
+
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [plugins.remarkCodeTab, remarkCodeTabOptions],
|
|
26
|
+
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
27
|
+
...v,
|
|
28
|
+
remarkStructureOptions !== false && [plugins.remarkStructure, {
|
|
29
|
+
exportAs: "structuredData",
|
|
30
|
+
...remarkStructureOptions
|
|
31
|
+
}],
|
|
32
|
+
valueToExport.length > 0 && (() => {
|
|
33
|
+
return (_, file) => {
|
|
34
|
+
file.data["mdx-export"] ??= [];
|
|
35
|
+
for (const name of valueToExport) {
|
|
36
|
+
if (!(name in file.data)) continue;
|
|
37
|
+
file.data["mdx-export"].push({
|
|
38
|
+
name,
|
|
39
|
+
value: file.data[name]
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
})
|
|
44
|
+
], mdxOptions.remarkPlugins);
|
|
45
|
+
const rehypePlugins = pluginOption((v) => [
|
|
46
|
+
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
47
|
+
...v,
|
|
48
|
+
plugins.rehypeToc
|
|
49
|
+
], mdxOptions.rehypePlugins);
|
|
50
|
+
return {
|
|
51
|
+
...mdxOptions,
|
|
52
|
+
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
53
|
+
remarkPlugins,
|
|
54
|
+
rehypePlugins
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
//#endregion
|
|
59
|
+
export { applyMdxPreset as t };
|
package/dist/rolldown/index.d.ts
CHANGED
package/dist/rolldown/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
2
|
import { i as buildConfig, t as createCore } from "../core-DV3f7rXs.js";
|
|
3
3
|
import { r as slash } from "../codegen-DfCJFqO-.js";
|
|
4
|
-
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-
|
|
4
|
+
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-BUIa-1SI.js";
|
|
5
5
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
6
6
|
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
7
7
|
import { r as resolveMacroOptions, t as MacroModuleId } from "../options-BNnYUjkM.js";
|
|
8
|
-
import { n as createNodeEvaluator, t as MacroCollector } from "../eval-
|
|
8
|
+
import { n as createNodeEvaluator, t as MacroCollector } from "../eval-Cnxpyc4j.js";
|
|
9
9
|
import fs from "node:fs/promises";
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
//#region src/rolldown/index.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as DocsCollection, j as CompiledMDXProperties, y as DocCollection } from "../core-
|
|
1
|
+
import { C as DocsCollection, j as CompiledMDXProperties, y as DocCollection } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { a as InternalTypeConfig } from "../types-1n7Fk5Dl.js";
|
|
3
3
|
import { FC, ReactNode } from "react";
|
|
4
4
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
@@ -37,4 +37,5 @@ export declare function browser<Config, TC extends InternalTypeConfig>(): {
|
|
|
37
37
|
doc<Name extends keyof Config & string>(_name: Name, glob: Record<string, () => Promise<unknown>>): Config[Name] extends DocCollection<infer Schema> | DocsCollection<infer Schema> ? DocCollectionEntry<Name, StandardSchemaV1.InferOutput<Schema>, TC> : never;
|
|
38
38
|
};
|
|
39
39
|
export declare function createClientLoader<Doc = CompiledMDXProperties, Props extends object | undefined = undefined>(globEntries: Record<string, () => Promise<Doc>>, options: ClientLoaderOptions<Doc, Props>): ClientLoader<Doc, Props>;
|
|
40
|
-
//#endregion
|
|
40
|
+
//#endregion
|
|
41
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as DocsCollection, r as CoreOptions, y as DocCollection } from "../core-
|
|
2
|
-
import "../index
|
|
1
|
+
import { C as DocsCollection, r as CoreOptions, y as DocCollection } from "../core-w3CkO8cV.js";
|
|
2
|
+
import "../config/index.js";
|
|
3
3
|
import { a as InternalTypeConfig, r as FileInfo } from "../types-1n7Fk5Dl.js";
|
|
4
4
|
import { AsyncDocCollectionEntry, AsyncDocsCollectionEntry } from "./server.js";
|
|
5
5
|
//#region src/runtime/dynamic.d.ts
|
package/dist/runtime/dynamic.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { i as buildConfig, t as createCore } from "../core-DV3f7rXs.js";
|
|
2
|
-
import { t as buildMDX } from "../build-
|
|
2
|
+
import { t as buildMDX } from "../build-DXxE3Ml4.js";
|
|
3
3
|
import { server } from "./server.js";
|
|
4
4
|
import { frontmatter } from "fumadocs-core/content/md/frontmatter";
|
|
5
5
|
import fs from "node:fs/promises";
|
package/dist/runtime/macro.d.ts
CHANGED
package/dist/runtime/server.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as DocsCollection, T as MetaCollection, y as DocCollection } from "../core-
|
|
2
|
-
import "../index
|
|
1
|
+
import { C as DocsCollection, T as MetaCollection, y as DocCollection } from "../core-w3CkO8cV.js";
|
|
2
|
+
import "../config/index.js";
|
|
3
3
|
import { a as InternalTypeConfig, n as DocMethods, o as MetaMethods, t as DocData } from "../types-1n7Fk5Dl.js";
|
|
4
4
|
import { MetaData, PageData, Source } from "fumadocs-core/source";
|
|
5
5
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
@@ -44,4 +44,5 @@ export declare function toFumadocsSource<Page extends DocMethods & PageData, Met
|
|
|
44
44
|
pageData: Page;
|
|
45
45
|
metaData: Meta;
|
|
46
46
|
}>;
|
|
47
|
-
//#endregion
|
|
47
|
+
//#endregion
|
|
48
|
+
export {};
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { p as IndexFilePluginOptions, r as CoreOptions, w as GlobalConfig } from "../core-
|
|
1
|
+
import { p as IndexFilePluginOptions, r as CoreOptions, w as GlobalConfig } from "../core-w3CkO8cV.js";
|
|
2
2
|
import { t as MacroPluginOption } from "../options-aB6xV-d7.js";
|
|
3
|
-
import "../index
|
|
3
|
+
import "../config/index.js";
|
|
4
4
|
import { Plugin } from "vite";
|
|
5
5
|
//#region src/vite/index.d.ts
|
|
6
6
|
export interface PluginOptions extends Pick<CoreOptions, 'configPath' | 'outDir' | 'plugins'> {
|
package/dist/vite/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
2
|
import { i as buildConfig, t as createCore } from "../core-DV3f7rXs.js";
|
|
3
|
-
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-
|
|
3
|
+
import { a as createIntegratedConfigLoader, r as toVite } from "../adapter-BUIa-1SI.js";
|
|
4
4
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
5
5
|
import { r as metaLoaderGlob, t as mdxLoaderGlob } from "../loaders-DWC_Uwqq.js";
|
|
6
6
|
import { r as resolveMacroOptions, t as MacroModuleId } from "../options-BNnYUjkM.js";
|
|
@@ -50,7 +50,7 @@ function mdx(forcedConfig, pluginOptions = {}) {
|
|
|
50
50
|
const core = managed.core;
|
|
51
51
|
const macroOptions = resolveMacroOptions(pluginOptions.macro);
|
|
52
52
|
if (macroOptions) {
|
|
53
|
-
const { MacroCollector } = await import("../eval-
|
|
53
|
+
const { MacroCollector } = await import("../eval-Cnxpyc4j.js").then((n) => n.r);
|
|
54
54
|
core.macro = new MacroCollector({
|
|
55
55
|
root: core.root,
|
|
56
56
|
outDir: core.outDir,
|
package/dist/webpack/macro.d.ts
CHANGED
package/dist/webpack/mdx.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as WebpackLoaderOptions } from "../index-
|
|
1
|
+
import { t as WebpackLoaderOptions } from "../index-C8JoWO0_.js";
|
|
2
2
|
import { LoaderDefinitionFunction } from "webpack";
|
|
3
3
|
//#region src/webpack/mdx.d.ts
|
|
4
4
|
declare const loader: LoaderDefinitionFunction<WebpackLoaderOptions>;
|
package/dist/webpack/mdx.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { t as createMdxLoader } from "../mdx-
|
|
2
|
-
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-
|
|
3
|
-
import { t as getCore } from "../webpack-
|
|
1
|
+
import { t as createMdxLoader } from "../mdx-Cmy8JCce.js";
|
|
2
|
+
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-BUIa-1SI.js";
|
|
3
|
+
import { t as getCore } from "../webpack-BozYCamo.js";
|
|
4
4
|
//#region src/webpack/mdx.ts
|
|
5
5
|
let instance;
|
|
6
6
|
const loader = function loader(source) {
|
package/dist/webpack/meta.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as WebpackLoaderOptions } from "../index-
|
|
1
|
+
import { t as WebpackLoaderOptions } from "../index-C8JoWO0_.js";
|
|
2
2
|
import { LoaderDefinitionFunction } from "webpack";
|
|
3
3
|
//#region src/webpack/meta.d.ts
|
|
4
4
|
declare const loader: LoaderDefinitionFunction<WebpackLoaderOptions>;
|
package/dist/webpack/meta.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-
|
|
1
|
+
import { i as toWebpack, o as createStandaloneConfigLoader } from "../adapter-BUIa-1SI.js";
|
|
2
2
|
import { t as createMetaLoader } from "../meta-BR_rkCyY.js";
|
|
3
|
-
import { t as getCore } from "../webpack-
|
|
3
|
+
import { t as getCore } from "../webpack-BozYCamo.js";
|
|
4
4
|
//#region src/webpack/meta.ts
|
|
5
5
|
const instances = /* @__PURE__ */ new Map();
|
|
6
6
|
const loader = function(source) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as createCore } from "./core-DV3f7rXs.js";
|
|
2
|
-
import { n as createNodeEvaluator, t as MacroCollector } from "./eval-
|
|
2
|
+
import { n as createNodeEvaluator, t as MacroCollector } from "./eval-Cnxpyc4j.js";
|
|
3
3
|
//#region src/webpack/index.ts
|
|
4
4
|
let core;
|
|
5
5
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-mdx",
|
|
3
|
-
"version": "15.4.
|
|
3
|
+
"version": "15.4.10",
|
|
4
4
|
"description": "The built-in source for Fumadocs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Docs",
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"@mdx-js/mdx": "^3.1.1",
|
|
58
58
|
"@standard-schema/spec": "^1.1.0",
|
|
59
|
-
"chokidar": "^
|
|
59
|
+
"chokidar": "^6.0.0",
|
|
60
60
|
"esbuild": "^0.28.2",
|
|
61
61
|
"estree-util-value-to-estree": "^3.5.0",
|
|
62
62
|
"github-slugger": "^2.0.0",
|
|
63
|
-
"magic-string": "^1.4.
|
|
63
|
+
"magic-string": "^1.4.3",
|
|
64
64
|
"mdast-util-mdx": "^3.0.0",
|
|
65
65
|
"picocolors": "^1.1.1",
|
|
66
66
|
"picomatch": "^4.0.7",
|
|
@@ -70,38 +70,38 @@
|
|
|
70
70
|
"unist-util-remove-position": "^5.0.0",
|
|
71
71
|
"vfile": "^6.0.3",
|
|
72
72
|
"yaml": "^2.9.1",
|
|
73
|
-
"yuku-analyzer": "^0.
|
|
74
|
-
"zod": "^4.6.
|
|
73
|
+
"yuku-analyzer": "^0.19.0",
|
|
74
|
+
"zod": "^4.6.7"
|
|
75
75
|
},
|
|
76
76
|
"devDependencies": {
|
|
77
|
-
"@fumadocs/satteri": "0.
|
|
77
|
+
"@fumadocs/satteri": "0.7.0",
|
|
78
78
|
"@fumadocs/vite": "0.1.0",
|
|
79
|
-
"@types/bun": "^1.4.
|
|
79
|
+
"@types/bun": "^1.4.3",
|
|
80
80
|
"@types/mdast": "^4.0.4",
|
|
81
81
|
"@types/mdx": "^2.0.14",
|
|
82
|
-
"@types/node": "^26.6.
|
|
82
|
+
"@types/node": "^26.6.5",
|
|
83
83
|
"@types/picomatch": "^4.0.3",
|
|
84
84
|
"@types/react": "^19.3.0",
|
|
85
|
-
"fumadocs-core": "16.17.
|
|
86
|
-
"mdast-util-directive": "^3.1.
|
|
87
|
-
"next": "^16.
|
|
88
|
-
"react": "^19.3.
|
|
85
|
+
"fumadocs-core": "16.17.8",
|
|
86
|
+
"mdast-util-directive": "^3.1.1",
|
|
87
|
+
"next": "^16.4.2",
|
|
88
|
+
"react": "^19.3.1",
|
|
89
89
|
"remark": "^15.0.1",
|
|
90
90
|
"remark-directive": "^4.0.0",
|
|
91
91
|
"remark-mdx": "^3.1.1",
|
|
92
|
-
"rolldown": "^1.2.
|
|
92
|
+
"rolldown": "^1.2.15",
|
|
93
93
|
"satteri": "^0.10.5",
|
|
94
94
|
"tsconfig": "0.0.0",
|
|
95
|
-
"tsdown": "0.23.
|
|
96
|
-
"vite": "^8.3.
|
|
97
|
-
"webpack": "^5.
|
|
95
|
+
"tsdown": "0.23.1",
|
|
96
|
+
"vite": "^8.3.5",
|
|
97
|
+
"webpack": "^5.112.0"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
100
|
"@fumadocs/satteri": "0.x.x",
|
|
101
101
|
"@types/mdast": "*",
|
|
102
102
|
"@types/mdx": "*",
|
|
103
103
|
"@types/react": "*",
|
|
104
|
-
"fumadocs-core": "^16.17.
|
|
104
|
+
"fumadocs-core": "^16.17.8",
|
|
105
105
|
"mdast-util-directive": "*",
|
|
106
106
|
"next": "^15.3.0 || ^16.0.0",
|
|
107
107
|
"react": "^19.2.0",
|
package/dist/index-DosG5f9I.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import "./core-6H7qqwEM.js";
|
|
2
|
-
import { Processor, Transformer } from "unified";
|
|
3
|
-
import { Root } from "mdast";
|
|
4
|
-
//#region src/loaders/mdx/remark-include.d.ts
|
|
5
|
-
declare function remarkInclude(this: Processor): Transformer<Root, Root>;
|
|
6
|
-
//#endregion
|
|
7
|
-
//#region src/config/index.d.ts
|
|
8
|
-
/** @deprecated import `pageSchema` from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
9
|
-
declare const frontmatterSchema: import("zod").ZodObject<{
|
|
10
|
-
title: import("zod").ZodString;
|
|
11
|
-
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
12
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
13
|
-
full: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
14
|
-
_openapi: import("zod").ZodOptional<import("zod").ZodRecord<import("zod").ZodString, import("zod").ZodCustom<import("fumadocs-core/source/schema")._JSONType, import("fumadocs-core/source/schema")._JSONType>>>;
|
|
15
|
-
}, import("zod/v4/core").$strip>;
|
|
16
|
-
/** @deprecated import from `fumadocs-core/source/schema` instead (since 16.2.3) */
|
|
17
|
-
declare const metaSchema: import("zod").ZodObject<{
|
|
18
|
-
title: import("zod").ZodOptional<import("zod").ZodString>;
|
|
19
|
-
pages: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString>>;
|
|
20
|
-
pagesIndex: import("zod").ZodOptional<import("zod").ZodString>;
|
|
21
|
-
description: import("zod").ZodOptional<import("zod").ZodString>;
|
|
22
|
-
root: import("zod").ZodOptional<import("zod").ZodUnion<readonly [import("zod").ZodBoolean, import("zod").ZodString]>>;
|
|
23
|
-
defaultOpen: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
24
|
-
collapsible: import("zod").ZodOptional<import("zod").ZodBoolean>;
|
|
25
|
-
icon: import("zod").ZodOptional<import("zod").ZodString>;
|
|
26
|
-
}, import("zod/v4/core").$strip>;
|
|
27
|
-
//#endregion
|
|
28
|
-
export { metaSchema as n, remarkInclude as r, frontmatterSchema as t };
|
|
@@ -1,318 +0,0 @@
|
|
|
1
|
-
import { frontmatter } from "fumadocs-core/content/md/frontmatter";
|
|
2
|
-
import * as fs$1 from "node:fs/promises";
|
|
3
|
-
import * as path$1 from "node:path";
|
|
4
|
-
import { unified } from "unified";
|
|
5
|
-
import { remarkHeading } from "fumadocs-core/mdx-plugins";
|
|
6
|
-
import { VFile } from "vfile";
|
|
7
|
-
import { embedSource, replaceSource } from "fumadocs-core/mdx-plugins/stringifier";
|
|
8
|
-
//#region src/config/preset.ts
|
|
9
|
-
function pluginOption(def, options = []) {
|
|
10
|
-
const list = def(Array.isArray(options) ? options : []).filter(Boolean);
|
|
11
|
-
if (typeof options === "function") return options(list);
|
|
12
|
-
return list;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* apply MDX processor presets
|
|
16
|
-
*/
|
|
17
|
-
function applyMdxPreset(options = {}) {
|
|
18
|
-
return async (environment = "bundler") => {
|
|
19
|
-
if (options.preset === "minimal") return options;
|
|
20
|
-
const plugins = await import("fumadocs-core/mdx-plugins");
|
|
21
|
-
const { valueToExport = [], rehypeCodeOptions, remarkImageOptions, remarkHeadingOptions, remarkStructureOptions, remarkCodeTabOptions, remarkNpmOptions, ...mdxOptions } = options;
|
|
22
|
-
const remarkPlugins = pluginOption((v) => [
|
|
23
|
-
plugins.remarkGfm,
|
|
24
|
-
[plugins.remarkHeading, {
|
|
25
|
-
generateToc: false,
|
|
26
|
-
...remarkHeadingOptions
|
|
27
|
-
}],
|
|
28
|
-
remarkImageOptions !== false && [plugins.remarkImage, {
|
|
29
|
-
...remarkImageOptions,
|
|
30
|
-
useImport: remarkImageOptions?.useImport ?? environment === "bundler"
|
|
31
|
-
}],
|
|
32
|
-
"remarkCodeTab" in plugins && remarkCodeTabOptions !== false && [plugins.remarkCodeTab, remarkCodeTabOptions],
|
|
33
|
-
"remarkNpm" in plugins && remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
|
34
|
-
...v,
|
|
35
|
-
remarkStructureOptions !== false && [plugins.remarkStructure, {
|
|
36
|
-
exportAs: "structuredData",
|
|
37
|
-
...remarkStructureOptions
|
|
38
|
-
}],
|
|
39
|
-
valueToExport.length > 0 && (() => {
|
|
40
|
-
return (_, file) => {
|
|
41
|
-
file.data["mdx-export"] ??= [];
|
|
42
|
-
for (const name of valueToExport) {
|
|
43
|
-
if (!(name in file.data)) continue;
|
|
44
|
-
file.data["mdx-export"].push({
|
|
45
|
-
name,
|
|
46
|
-
value: file.data[name]
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
})
|
|
51
|
-
], mdxOptions.remarkPlugins);
|
|
52
|
-
const rehypePlugins = pluginOption((v) => [
|
|
53
|
-
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
|
54
|
-
...v,
|
|
55
|
-
plugins.rehypeToc
|
|
56
|
-
], mdxOptions.rehypePlugins);
|
|
57
|
-
return {
|
|
58
|
-
...mdxOptions,
|
|
59
|
-
outputFormat: environment === "runtime" ? "function-body" : mdxOptions.outputFormat,
|
|
60
|
-
remarkPlugins,
|
|
61
|
-
rehypePlugins
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/loaders/mdx/mdast-utils.ts
|
|
67
|
-
function flattenNode(node) {
|
|
68
|
-
if ("children" in node) return node.children.map((child) => flattenNode(child)).join("");
|
|
69
|
-
if ("value" in node) return node.value;
|
|
70
|
-
return "";
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Visit a tree in document order, returning `skip` skips the children of a node and `false` stops the walk.
|
|
74
|
-
*/
|
|
75
|
-
function walk(node, visitor, index, parent) {
|
|
76
|
-
const result = visitor(node, index, parent);
|
|
77
|
-
if (result === false) return false;
|
|
78
|
-
if (result !== "skip" && node.children) {
|
|
79
|
-
for (let i = 0; i < node.children.length; i++) if (!walk(node.children[i], visitor, i, node)) return false;
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
}
|
|
83
|
-
//#endregion
|
|
84
|
-
//#region src/loaders/mdx/remark-unravel.ts
|
|
85
|
-
function remarkMarkAndUnravel() {
|
|
86
|
-
return (tree) => {
|
|
87
|
-
walk(tree, (node, index, parent) => {
|
|
88
|
-
let offset = -1;
|
|
89
|
-
let all = true;
|
|
90
|
-
let oneOrMore = false;
|
|
91
|
-
if (parent && typeof index === "number" && node.type === "paragraph") {
|
|
92
|
-
const children = node.children;
|
|
93
|
-
while (++offset < children.length) {
|
|
94
|
-
const child = children[offset];
|
|
95
|
-
if (child.type === "mdxJsxTextElement" || child.type === "mdxTextExpression") oneOrMore = true;
|
|
96
|
-
else if (child.type === "text" && child.value.trim().length === 0) {} else {
|
|
97
|
-
all = false;
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
if (all && oneOrMore) {
|
|
102
|
-
offset = -1;
|
|
103
|
-
const newChildren = [];
|
|
104
|
-
while (++offset < children.length) {
|
|
105
|
-
const child = children[offset];
|
|
106
|
-
if (child.type === "mdxJsxTextElement") child.type = "mdxJsxFlowElement";
|
|
107
|
-
if (child.type === "mdxTextExpression") child.type = "mdxFlowExpression";
|
|
108
|
-
if (child.type === "text" && /^[\t\r\n ]+$/.test(String(child.value))) {} else newChildren.push(child);
|
|
109
|
-
}
|
|
110
|
-
parent.children.splice(index, 1, ...newChildren);
|
|
111
|
-
return "skip";
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
//#endregion
|
|
118
|
-
//#region src/loaders/mdx/remark-include.ts
|
|
119
|
-
/**
|
|
120
|
-
* VS Code–style region extraction
|
|
121
|
-
* Adapted from VitePress:
|
|
122
|
-
* https://github.com/vuejs/vitepress/blob/main/src/node/markdown/plugins/snippet.ts
|
|
123
|
-
*/
|
|
124
|
-
const REGION_MARKERS = [
|
|
125
|
-
{
|
|
126
|
-
start: /^\s*\/\/\s*#?region\b\s*(.*?)\s*$/,
|
|
127
|
-
end: /^\s*\/\/\s*#?endregion\b\s*(.*?)\s*$/
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
start: /^\s*<!--\s*#?region\b\s*(.*?)\s*-->/,
|
|
131
|
-
end: /^\s*<!--\s*#?endregion\b\s*(.*?)\s*-->/
|
|
132
|
-
},
|
|
133
|
-
{
|
|
134
|
-
start: /^\s*\/\*\s*#region\b\s*(.*?)\s*\*\//,
|
|
135
|
-
end: /^\s*\/\*\s*#endregion\b\s*(.*?)\s*\*\//
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
start: /^\s*#[rR]egion\b\s*(.*?)\s*$/,
|
|
139
|
-
end: /^\s*#[eE]nd ?[rR]egion\b\s*(.*?)\s*$/
|
|
140
|
-
},
|
|
141
|
-
{
|
|
142
|
-
start: /^\s*#\s*#?region\b\s*(.*?)\s*$/,
|
|
143
|
-
end: /^\s*#\s*#?endregion\b\s*(.*?)\s*$/
|
|
144
|
-
},
|
|
145
|
-
{
|
|
146
|
-
start: /^\s*(?:--|::|@?REM)\s*#region\b\s*(.*?)\s*$/,
|
|
147
|
-
end: /^\s*(?:--|::|@?REM)\s*#endregion\b\s*(.*?)\s*$/
|
|
148
|
-
},
|
|
149
|
-
{
|
|
150
|
-
start: /^\s*#pragma\s+region\b\s*(.*?)\s*$/,
|
|
151
|
-
end: /^\s*#pragma\s+endregion\b\s*(.*?)\s*$/
|
|
152
|
-
},
|
|
153
|
-
{
|
|
154
|
-
start: /^\s*\(\*\s*#region\b\s*(.*?)\s*\*\)/,
|
|
155
|
-
end: /^\s*\(\*\s*#endregion\b\s*(.*?)\s*\*\)/
|
|
156
|
-
}
|
|
157
|
-
];
|
|
158
|
-
function dedent(lines) {
|
|
159
|
-
const minIndent = lines.reduce((min, line) => {
|
|
160
|
-
const match = line.match(/^(\s*)\S/);
|
|
161
|
-
return match ? Math.min(min, match[1].length) : min;
|
|
162
|
-
}, Infinity);
|
|
163
|
-
return minIndent === Infinity ? lines.join("\n") : lines.map((l) => l.slice(minIndent)).join("\n");
|
|
164
|
-
}
|
|
165
|
-
function extractCodeRegion(content, regionName) {
|
|
166
|
-
const lines = content.split("\n");
|
|
167
|
-
for (let i = 0; i < lines.length; i++) for (const re of REGION_MARKERS) {
|
|
168
|
-
let match = re.start.exec(lines[i]);
|
|
169
|
-
if (match?.[1] !== regionName) continue;
|
|
170
|
-
let depth = 1;
|
|
171
|
-
const extractedLines = [];
|
|
172
|
-
for (let j = i + 1; j < lines.length; j++) {
|
|
173
|
-
match = re.start.exec(lines[j]);
|
|
174
|
-
if (match) {
|
|
175
|
-
depth++;
|
|
176
|
-
continue;
|
|
177
|
-
}
|
|
178
|
-
match = re.end.exec(lines[j]);
|
|
179
|
-
if (match) {
|
|
180
|
-
if (match[1] === regionName) depth = 0;
|
|
181
|
-
else if (match[1] === "") depth--;
|
|
182
|
-
else continue;
|
|
183
|
-
if (depth > 0) continue;
|
|
184
|
-
return dedent(extractedLines);
|
|
185
|
-
} else extractedLines.push(lines[j]);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
throw new Error(`Region "${regionName}" not found`);
|
|
189
|
-
}
|
|
190
|
-
const ElementLikeTypes = [
|
|
191
|
-
"mdxJsxFlowElement",
|
|
192
|
-
"mdxJsxTextElement",
|
|
193
|
-
"containerDirective",
|
|
194
|
-
"textDirective",
|
|
195
|
-
"leafDirective"
|
|
196
|
-
];
|
|
197
|
-
function isElementLike(node) {
|
|
198
|
-
return ElementLikeTypes.includes(node.type);
|
|
199
|
-
}
|
|
200
|
-
function parseElementAttributes(element) {
|
|
201
|
-
if (Array.isArray(element.attributes)) {
|
|
202
|
-
const attributes = {};
|
|
203
|
-
for (const attr of element.attributes) if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) attributes[attr.name] = attr.value;
|
|
204
|
-
return attributes;
|
|
205
|
-
}
|
|
206
|
-
return element.attributes ?? {};
|
|
207
|
-
}
|
|
208
|
-
function parseSpecifier(specifier) {
|
|
209
|
-
const idx = specifier.lastIndexOf("#");
|
|
210
|
-
if (idx === -1) return { file: specifier };
|
|
211
|
-
return {
|
|
212
|
-
file: specifier.slice(0, idx),
|
|
213
|
-
section: specifier.slice(idx + 1)
|
|
214
|
-
};
|
|
215
|
-
}
|
|
216
|
-
function extractSection(root, section) {
|
|
217
|
-
let nodes;
|
|
218
|
-
let capturingHeadingContent = false;
|
|
219
|
-
walk(root, (node) => {
|
|
220
|
-
if (node.type === "heading") {
|
|
221
|
-
if (capturingHeadingContent) return false;
|
|
222
|
-
if (node.data?.hProperties?.id === section) {
|
|
223
|
-
capturingHeadingContent = true;
|
|
224
|
-
nodes = [node];
|
|
225
|
-
return "skip";
|
|
226
|
-
}
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (capturingHeadingContent) {
|
|
230
|
-
nodes?.push(node);
|
|
231
|
-
return "skip";
|
|
232
|
-
}
|
|
233
|
-
if (isElementLike(node) && node.name === "section") {
|
|
234
|
-
if (parseElementAttributes(node).id === section) {
|
|
235
|
-
nodes = node.children;
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
if (nodes) return {
|
|
241
|
-
type: "root",
|
|
242
|
-
children: nodes
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
function remarkInclude() {
|
|
246
|
-
const TagName = "include";
|
|
247
|
-
const embedContent = async (target, targetPath, heading, params, parent, root) => {
|
|
248
|
-
const { _getProcessor = () => this, _compiler } = parent.data;
|
|
249
|
-
let content;
|
|
250
|
-
try {
|
|
251
|
-
content = await fs$1.readFile(targetPath, "utf-8");
|
|
252
|
-
} catch (e) {
|
|
253
|
-
throw new Error(`failed to read file ${targetPath}\n${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
254
|
-
}
|
|
255
|
-
const ext = path$1.extname(targetPath);
|
|
256
|
-
_compiler?.addDependency(targetPath);
|
|
257
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
258
|
-
const lang = params.lang ?? ext.slice(1);
|
|
259
|
-
let value = content;
|
|
260
|
-
if (heading) value = extractCodeRegion(content, heading.trim());
|
|
261
|
-
let fence = "```";
|
|
262
|
-
while (value.includes(fence)) fence += "`";
|
|
263
|
-
replaceSource(root, target, `${fence}${lang}${params.meta ? ` ${params.meta}` : ""}\n${value.replace(/\r?\n$/, "")}\n${fence}`);
|
|
264
|
-
return {
|
|
265
|
-
type: "code",
|
|
266
|
-
lang,
|
|
267
|
-
meta: params.meta,
|
|
268
|
-
value,
|
|
269
|
-
data: {}
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
const parser = _getProcessor(ext === ".mdx" ? "mdx" : "md");
|
|
273
|
-
const parsed = frontmatter(content);
|
|
274
|
-
const targetFile = new VFile({
|
|
275
|
-
path: targetPath,
|
|
276
|
-
value: parsed.content,
|
|
277
|
-
data: {
|
|
278
|
-
...parent.data,
|
|
279
|
-
frontmatter: parsed.data
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
let mdast = parser.parse(targetFile);
|
|
283
|
-
const baseProcessor = unified().use(remarkMarkAndUnravel);
|
|
284
|
-
if (heading) {
|
|
285
|
-
const extracted = extractSection(await baseProcessor.use(remarkHeading).run(mdast), heading);
|
|
286
|
-
if (!extracted) throw new Error(`Cannot find section ${heading} in ${targetPath}, make sure you have encapsulated the section in a <section id="${heading}"> tag, or a :::section directive with remark-directive configured.`);
|
|
287
|
-
mdast = extracted;
|
|
288
|
-
} else mdast = await baseProcessor.run(mdast);
|
|
289
|
-
embedSource(root, target, parsed.content, mdast.children);
|
|
290
|
-
await update(mdast, targetFile, root);
|
|
291
|
-
return mdast;
|
|
292
|
-
};
|
|
293
|
-
async function update(tree, file, root) {
|
|
294
|
-
const queue = [];
|
|
295
|
-
walk(tree, (node, _, parent) => {
|
|
296
|
-
if (!isElementLike(node) || node.name !== TagName) return;
|
|
297
|
-
const specifier = flattenNode(node);
|
|
298
|
-
if (specifier.length === 0) return "skip";
|
|
299
|
-
const attributes = parseElementAttributes(node);
|
|
300
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
301
|
-
const targetPath = path$1.resolve("cwd" in attributes || !file.dirname ? file.cwd : file.dirname, relativePath);
|
|
302
|
-
const host = parent;
|
|
303
|
-
const target = host?.type === "paragraph" ? host : node;
|
|
304
|
-
queue.push(embedContent(target, targetPath, section, attributes, file, root).then((replace) => {
|
|
305
|
-
const { position } = target;
|
|
306
|
-
for (const key in target) delete target[key];
|
|
307
|
-
Object.assign(target, replace, { position });
|
|
308
|
-
}));
|
|
309
|
-
return "skip";
|
|
310
|
-
});
|
|
311
|
-
await Promise.all(queue);
|
|
312
|
-
}
|
|
313
|
-
return async (tree, file) => {
|
|
314
|
-
await update(tree, file, file);
|
|
315
|
-
};
|
|
316
|
-
}
|
|
317
|
-
//#endregion
|
|
318
|
-
export { applyMdxPreset as i, flattenNode as n, walk as r, remarkInclude as t };
|