fumadocs-core 16.8.6 → 16.8.8
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/content/md.js +7 -9
- package/package.json +1 -1
package/dist/content/md.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { use } from "react";
|
|
1
|
+
import { use, useMemo } from "react";
|
|
2
2
|
import * as JsxRuntime from "react/jsx-runtime";
|
|
3
3
|
import { remark } from "remark";
|
|
4
4
|
import remarkRehype from "remark-rehype";
|
|
@@ -7,7 +7,6 @@ import { toJsxRuntime } from "hast-util-to-jsx-runtime";
|
|
|
7
7
|
//#region src/content/md.ts
|
|
8
8
|
function createMarkdownRenderer({ rehypePlugins = [], remarkPlugins = [], remarkRehypeOptions } = {}) {
|
|
9
9
|
const processor = remark().use(remarkPlugins).use(remarkRehype, remarkRehypeOptions).use(rehypePlugins);
|
|
10
|
-
const cache = {};
|
|
11
10
|
const promises = {};
|
|
12
11
|
function render(tree, file, props) {
|
|
13
12
|
return toJsxRuntime(tree, {
|
|
@@ -17,24 +16,23 @@ function createMarkdownRenderer({ rehypePlugins = [], remarkPlugins = [], remark
|
|
|
17
16
|
...JsxRuntime
|
|
18
17
|
});
|
|
19
18
|
}
|
|
20
|
-
function parse(file
|
|
19
|
+
function parse(file) {
|
|
21
20
|
return processor.parse(file);
|
|
22
21
|
}
|
|
23
22
|
return {
|
|
24
23
|
Markdown(props) {
|
|
25
24
|
const { async = false, children } = props;
|
|
26
25
|
const file = new VFile(children);
|
|
27
|
-
const
|
|
26
|
+
const id = `${file.path}:${file.value}`;
|
|
28
27
|
if (async) {
|
|
29
|
-
promises[
|
|
30
|
-
return render(use(promises[
|
|
28
|
+
promises[id] ??= processor.run(parse(file), file);
|
|
29
|
+
return render(use(promises[id]), file, props);
|
|
31
30
|
}
|
|
32
|
-
|
|
33
|
-
return render(cache[key], file, props);
|
|
31
|
+
return render(useMemo(() => processor.runSync(parse(file), file), [id]), file, props);
|
|
34
32
|
},
|
|
35
33
|
async MarkdownServer(props) {
|
|
36
34
|
const file = new VFile(props.children);
|
|
37
|
-
return render(await processor.run(parse(file
|
|
35
|
+
return render(await processor.run(parse(file), file), file, props);
|
|
38
36
|
}
|
|
39
37
|
};
|
|
40
38
|
}
|