fumadocs-mdx 12.0.0 → 12.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.
- package/dist/bin.cjs +102 -84
- package/dist/bin.js +1 -1
- package/dist/bun/index.cjs +156 -130
- package/dist/bun/index.js +8 -8
- package/dist/chunk-ADR6R7HM.js +29 -0
- package/dist/{chunk-3M4SHY6K.js → chunk-FSZMKRVH.js} +1 -1
- package/dist/{chunk-POXTQZ4D.js → chunk-LGYVNESJ.js} +2 -6
- package/dist/chunk-LMG6UWCL.js +167 -0
- package/dist/{chunk-SWNOXPYJ.js → chunk-QAUWMR5D.js} +6 -6
- package/dist/{chunk-KGUBBRL6.js → chunk-SP7CHRTS.js} +9 -37
- package/dist/{chunk-YC25YEBF.js → chunk-U4MQ44TS.js} +1 -1
- package/dist/chunk-XMFLD5J6.js +30 -0
- package/dist/{chunk-TLD6JMT6.js → chunk-ZX7TM4AR.js} +4 -2
- package/dist/config/index.cjs +84 -56
- package/dist/config/index.js +2 -2
- package/dist/load-UUXLUBHL.js +9 -0
- package/dist/loader-mdx.cjs +217 -174
- package/dist/loader-mdx.js +7 -7
- package/dist/next/index.cjs +128 -108
- package/dist/next/index.js +39 -53
- package/dist/node/loader.cjs +152 -109
- package/dist/node/loader.js +6 -7
- package/dist/postinstall-SCSXM4IM.js +10 -0
- package/dist/{preset-WFEORCAB.js → preset-ZMP6U62C.js} +1 -1
- package/dist/runtime/next/async.cjs +117 -65
- package/dist/runtime/next/async.d.cts +1 -1
- package/dist/runtime/next/async.d.ts +1 -1
- package/dist/runtime/next/async.js +15 -8
- package/dist/runtime/next/index.d.cts +2 -2
- package/dist/runtime/next/index.d.ts +2 -2
- package/dist/{types-DLIAvrgC.d.ts → types-CFlQxTN8.d.ts} +4 -5
- package/dist/{types-Dl8HLbm5.d.cts → types-DkGjw-Uo.d.cts} +4 -5
- package/dist/vite/index.cjs +177 -145
- package/dist/vite/index.d.cts +1 -0
- package/dist/vite/index.d.ts +1 -0
- package/dist/vite/index.js +14 -19
- package/dist/{watcher-4NDMOH4R.js → watcher-HGOH3APP.js} +1 -1
- package/package.json +15 -11
- package/dist/chunk-KTDVTBMH.js +0 -139
- package/dist/postinstall-U7VROOY7.js +0 -9
package/dist/chunk-KTDVTBMH.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
fumaMatter
|
|
3
|
-
} from "./chunk-VWJKRQZR.js";
|
|
4
|
-
|
|
5
|
-
// src/mdx/remark-include.ts
|
|
6
|
-
import { unified } from "unified";
|
|
7
|
-
import { visit } from "unist-util-visit";
|
|
8
|
-
import * as path from "path";
|
|
9
|
-
import * as fs from "fs/promises";
|
|
10
|
-
import remarkParse from "remark-parse";
|
|
11
|
-
import remarkMdx from "remark-mdx";
|
|
12
|
-
import { remarkHeading } from "fumadocs-core/mdx-plugins";
|
|
13
|
-
var baseProcessor = unified().use(remarkHeading);
|
|
14
|
-
function flattenNode(node) {
|
|
15
|
-
if ("children" in node)
|
|
16
|
-
return node.children.map((child) => flattenNode(child)).join("");
|
|
17
|
-
if ("value" in node) return node.value;
|
|
18
|
-
return "";
|
|
19
|
-
}
|
|
20
|
-
function parseSpecifier(specifier) {
|
|
21
|
-
const idx = specifier.lastIndexOf("#");
|
|
22
|
-
if (idx === -1) return { file: specifier };
|
|
23
|
-
return {
|
|
24
|
-
file: specifier.slice(0, idx),
|
|
25
|
-
section: specifier.slice(idx + 1)
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
function extractSection(root, section) {
|
|
29
|
-
let nodes;
|
|
30
|
-
for (const node of root.children) {
|
|
31
|
-
if (node.type === "mdxJsxFlowElement" && node.name === "section" && node.attributes.some(
|
|
32
|
-
(attr) => attr.type === "mdxJsxAttribute" && attr.name === "id" && attr.value === section
|
|
33
|
-
)) {
|
|
34
|
-
nodes = node.children;
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
if (node.type === "heading" && node.data?.hProperties?.id === section) {
|
|
38
|
-
nodes = [node];
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
if (!nodes) continue;
|
|
42
|
-
if (node.type === "heading") break;
|
|
43
|
-
nodes.push(node);
|
|
44
|
-
}
|
|
45
|
-
if (nodes)
|
|
46
|
-
return {
|
|
47
|
-
type: "root",
|
|
48
|
-
children: nodes
|
|
49
|
-
};
|
|
50
|
-
}
|
|
51
|
-
function remarkInclude() {
|
|
52
|
-
const TagName = "include";
|
|
53
|
-
async function embedContent(file, heading, params, data) {
|
|
54
|
-
let content;
|
|
55
|
-
try {
|
|
56
|
-
content = (await fs.readFile(file)).toString();
|
|
57
|
-
} catch (e) {
|
|
58
|
-
throw new Error(
|
|
59
|
-
`failed to read file ${file}
|
|
60
|
-
${e instanceof Error ? e.message : String(e)}`,
|
|
61
|
-
{ cause: e }
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
const ext = path.extname(file);
|
|
65
|
-
data._compiler?.addDependency(file);
|
|
66
|
-
if (params.lang || ext !== ".md" && ext !== ".mdx") {
|
|
67
|
-
const lang = params.lang ?? ext.slice(1);
|
|
68
|
-
return {
|
|
69
|
-
type: "code",
|
|
70
|
-
lang,
|
|
71
|
-
meta: params.meta,
|
|
72
|
-
value: content,
|
|
73
|
-
data: {}
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
const processor = (data._getProcessor ?? getDefaultProcessor)(
|
|
77
|
-
ext === ".mdx" ? "mdx" : "md"
|
|
78
|
-
);
|
|
79
|
-
let parsed = await baseProcessor.run(
|
|
80
|
-
processor.parse(fumaMatter(content).content)
|
|
81
|
-
);
|
|
82
|
-
if (heading) {
|
|
83
|
-
const extracted = extractSection(parsed, heading);
|
|
84
|
-
if (!extracted)
|
|
85
|
-
throw new Error(
|
|
86
|
-
`Cannot find section ${heading} in ${file}, make sure you have encapsulated the section in a <section id="${heading}"> tag.`
|
|
87
|
-
);
|
|
88
|
-
parsed = extracted;
|
|
89
|
-
}
|
|
90
|
-
await update(parsed, path.dirname(file), data);
|
|
91
|
-
return parsed;
|
|
92
|
-
}
|
|
93
|
-
async function update(tree, directory, data) {
|
|
94
|
-
const queue = [];
|
|
95
|
-
visit(
|
|
96
|
-
tree,
|
|
97
|
-
["mdxJsxFlowElement", "mdxJsxTextElement"],
|
|
98
|
-
(_node, _, parent) => {
|
|
99
|
-
const node = _node;
|
|
100
|
-
if (node.name !== TagName) return;
|
|
101
|
-
const params = {};
|
|
102
|
-
const specifier = flattenNode(node);
|
|
103
|
-
if (specifier.length === 0) return "skip";
|
|
104
|
-
for (const attr of node.attributes) {
|
|
105
|
-
if (attr.type === "mdxJsxAttribute" && (typeof attr.value === "string" || attr.value === null)) {
|
|
106
|
-
params[attr.name] = attr.value;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
const { file: relativePath, section } = parseSpecifier(specifier);
|
|
110
|
-
const file = path.resolve(
|
|
111
|
-
"cwd" in params ? process.cwd() : directory,
|
|
112
|
-
relativePath
|
|
113
|
-
);
|
|
114
|
-
queue.push(
|
|
115
|
-
embedContent(file, section, params, data).then((replace) => {
|
|
116
|
-
Object.assign(
|
|
117
|
-
parent && parent.type === "paragraph" ? parent : node,
|
|
118
|
-
replace
|
|
119
|
-
);
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
return "skip";
|
|
123
|
-
}
|
|
124
|
-
);
|
|
125
|
-
await Promise.all(queue);
|
|
126
|
-
}
|
|
127
|
-
return async (tree, file) => {
|
|
128
|
-
await update(tree, path.dirname(file.path), file.data);
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
function getDefaultProcessor(format) {
|
|
132
|
-
const mdProcessor = unified().use(remarkParse);
|
|
133
|
-
if (format === "md") return mdProcessor;
|
|
134
|
-
return mdProcessor.use(remarkMdx);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
export {
|
|
138
|
-
remarkInclude
|
|
139
|
-
};
|