fumadocs-core 16.4.0 → 16.4.2
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/advanced-BRT5Ij43.js +80 -0
- package/dist/advanced-BRT5Ij43.js.map +1 -0
- package/dist/algolia-CBBN8R6-.d.ts +68 -0
- package/dist/algolia-CBBN8R6-.d.ts.map +1 -0
- package/dist/algolia-CQPXCnjV.js +49 -0
- package/dist/algolia-CQPXCnjV.js.map +1 -0
- package/dist/breadcrumb.d.ts +29 -27
- package/dist/breadcrumb.d.ts.map +1 -0
- package/dist/breadcrumb.js +55 -72
- package/dist/breadcrumb.js.map +1 -0
- package/dist/chunk-B-ezknvj.js +42 -0
- package/dist/codeblock-utils-lld8UiQo.d.ts +37 -0
- package/dist/codeblock-utils-lld8UiQo.d.ts.map +1 -0
- package/dist/content/github.d.ts +43 -32
- package/dist/content/github.d.ts.map +1 -0
- package/dist/content/github.js +29 -43
- package/dist/content/github.js.map +1 -0
- package/dist/content/index.d.ts +20 -13
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +17 -23
- package/dist/content/index.js.map +1 -0
- package/dist/content/mdx/preset-bundler.d.ts +22 -24
- package/dist/content/mdx/preset-bundler.d.ts.map +1 -0
- package/dist/content/mdx/preset-bundler.js +38 -69
- package/dist/content/mdx/preset-bundler.js.map +1 -0
- package/dist/content/mdx/preset-runtime.d.ts +22 -24
- package/dist/content/mdx/preset-runtime.d.ts.map +1 -0
- package/dist/content/mdx/preset-runtime.js +36 -68
- package/dist/content/mdx/preset-runtime.js.map +1 -0
- package/dist/content/toc.d.ts +7 -6
- package/dist/content/toc.d.ts.map +1 -0
- package/dist/content/toc.js +15 -19
- package/dist/content/toc.js.map +1 -0
- package/dist/definitions-DuxDer_c.d.ts +62 -0
- package/dist/definitions-DuxDer_c.d.ts.map +1 -0
- package/dist/dynamic-link.d.ts +7 -5
- package/dist/dynamic-link.d.ts.map +1 -0
- package/dist/dynamic-link.js +29 -27
- package/dist/dynamic-link.js.map +1 -0
- package/dist/fetch-B5e9CFfN.js +20 -0
- package/dist/fetch-B5e9CFfN.js.map +1 -0
- package/dist/framework/index.d.ts +38 -29
- package/dist/framework/index.d.ts.map +1 -0
- package/dist/framework/index.js +68 -17
- package/dist/framework/index.js.map +1 -0
- package/dist/framework/next.d.ts +15 -10
- package/dist/framework/next.d.ts.map +1 -0
- package/dist/framework/next.js +18 -26
- package/dist/framework/next.js.map +1 -0
- package/dist/framework/react-router.d.ts +15 -10
- package/dist/framework/react-router.d.ts.map +1 -0
- package/dist/framework/react-router.js +42 -55
- package/dist/framework/react-router.js.map +1 -0
- package/dist/framework/tanstack.d.ts +15 -10
- package/dist/framework/tanstack.d.ts.map +1 -0
- package/dist/framework/tanstack.js +54 -69
- package/dist/framework/tanstack.js.map +1 -0
- package/dist/framework/waku.d.ts +15 -10
- package/dist/framework/waku.d.ts.map +1 -0
- package/dist/framework/waku.js +47 -58
- package/dist/framework/waku.js.map +1 -0
- package/dist/highlight/client.d.ts +6 -7
- package/dist/highlight/client.d.ts.map +1 -0
- package/dist/highlight/client.js +22 -14
- package/dist/highlight/client.js.map +1 -0
- package/dist/highlight/index.d.ts +2 -30
- package/dist/highlight/index.js +3 -13
- package/dist/i18n/index.d.ts +2 -39
- package/dist/i18n/index.js +6 -7
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/middleware.d.ts +36 -28
- package/dist/i18n/middleware.d.ts.map +1 -0
- package/dist/i18n/middleware.js +55 -73
- package/dist/i18n/middleware.js.map +1 -0
- package/dist/icon-Dt7IObrc.js +19 -0
- package/dist/icon-Dt7IObrc.js.map +1 -0
- package/dist/index-2U6Tl4--.d.ts +379 -0
- package/dist/index-2U6Tl4--.d.ts.map +1 -0
- package/dist/index-Bw-DCOra.d.ts +41 -0
- package/dist/index-Bw-DCOra.d.ts.map +1 -0
- package/dist/link.d.ts +17 -15
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +29 -9
- package/dist/link.js.map +1 -0
- package/dist/mdast-utils-mc9-X-PK.js +40 -0
- package/dist/mdast-utils-mc9-X-PK.js.map +1 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +2 -29
- package/dist/mdx-plugins/codeblock-utils.js +71 -9
- package/dist/mdx-plugins/codeblock-utils.js.map +1 -0
- package/dist/mdx-plugins/index.d.ts +15 -20
- package/dist/mdx-plugins/index.js +18 -73
- package/dist/mdx-plugins/rehype-code.d.ts +2 -55
- package/dist/mdx-plugins/rehype-code.js +5 -15
- package/dist/mdx-plugins/rehype-toc.d.ts +2 -14
- package/dist/mdx-plugins/rehype-toc.js +3 -7
- package/dist/mdx-plugins/remark-admonition.d.ts +2 -20
- package/dist/mdx-plugins/remark-admonition.js +74 -8
- package/dist/mdx-plugins/remark-admonition.js.map +1 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +2 -30
- package/dist/mdx-plugins/remark-code-tab.js +183 -7
- package/dist/mdx-plugins/remark-code-tab.js.map +1 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -27
- package/dist/mdx-plugins/remark-directive-admonition.js +60 -7
- package/dist/mdx-plugins/remark-directive-admonition.js.map +1 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +2 -1
- package/dist/mdx-plugins/remark-gfm.js +3 -7
- package/dist/mdx-plugins/remark-heading.d.ts +2 -31
- package/dist/mdx-plugins/remark-heading.js +45 -8
- package/dist/mdx-plugins/remark-heading.js.map +1 -0
- package/dist/mdx-plugins/remark-image.d.ts +2 -57
- package/dist/mdx-plugins/remark-image.js +192 -7
- package/dist/mdx-plugins/remark-image.js.map +1 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -40
- package/dist/mdx-plugins/remark-mdx-files.js +187 -7
- package/dist/mdx-plugins/remark-mdx-files.js.map +1 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -15
- package/dist/mdx-plugins/remark-mdx-mermaid.js +31 -7
- package/dist/mdx-plugins/remark-mdx-mermaid.js.map +1 -0
- package/dist/mdx-plugins/remark-npm.d.ts +2 -31
- package/dist/mdx-plugins/remark-npm.js +68 -8
- package/dist/mdx-plugins/remark-npm.js.map +1 -0
- package/dist/mdx-plugins/remark-steps.d.ts +2 -23
- package/dist/mdx-plugins/remark-steps.js +77 -7
- package/dist/mdx-plugins/remark-steps.js.map +1 -0
- package/dist/mdx-plugins/remark-structure.d.ts +2 -71
- package/dist/mdx-plugins/remark-structure.js +105 -11
- package/dist/mdx-plugins/remark-structure.js.map +1 -0
- package/dist/mixedbread-DlByNYSd.js +88 -0
- package/dist/mixedbread-DlByNYSd.js.map +1 -0
- package/dist/negotiation/index.d.ts +6 -4
- package/dist/negotiation/index.d.ts.map +1 -0
- package/dist/negotiation/index.js +41 -11
- package/dist/negotiation/index.js.map +1 -0
- package/dist/normalize-url-DP9-1I-S.js +16 -0
- package/dist/normalize-url-DP9-1I-S.js.map +1 -0
- package/dist/orama-cloud-DH3g37zc.js +84 -0
- package/dist/orama-cloud-DH3g37zc.js.map +1 -0
- package/dist/page-tree/index.d.ts +23 -11
- package/dist/page-tree/index.d.ts.map +1 -0
- package/dist/page-tree/index.js +3 -17
- package/dist/path-DHIjrDBP.js +60 -0
- package/dist/path-DHIjrDBP.js.map +1 -0
- package/dist/rehype-code-CdiZ1Y6P.js +241 -0
- package/dist/rehype-code-CdiZ1Y6P.js.map +1 -0
- package/dist/rehype-code-vVWG4-ej.d.ts +58 -0
- package/dist/rehype-code-vVWG4-ej.d.ts.map +1 -0
- package/dist/rehype-toc-DJvSyE0o.d.ts +18 -0
- package/dist/rehype-toc-DJvSyE0o.d.ts.map +1 -0
- package/dist/rehype-toc-DVwJcwvA.js +143 -0
- package/dist/rehype-toc-DVwJcwvA.js.map +1 -0
- package/dist/remark-admonition-DOwBWzsH.d.ts +22 -0
- package/dist/remark-admonition-DOwBWzsH.d.ts.map +1 -0
- package/dist/remark-code-tab-CXsYlims.d.ts +32 -0
- package/dist/remark-code-tab-CXsYlims.d.ts.map +1 -0
- package/dist/remark-directive-admonition-BCm_yiU9.d.ts +36 -0
- package/dist/remark-directive-admonition-BCm_yiU9.d.ts.map +1 -0
- package/dist/remark-gfm-CeWpMwyk.d.ts +2 -0
- package/dist/remark-heading-CXvCY0go.d.ts +37 -0
- package/dist/remark-heading-CXvCY0go.d.ts.map +1 -0
- package/dist/remark-image-CvUis4R1.d.ts +65 -0
- package/dist/remark-image-CvUis4R1.d.ts.map +1 -0
- package/dist/remark-mdx-files-B31xFFG4.d.ts +56 -0
- package/dist/remark-mdx-files-B31xFFG4.d.ts.map +1 -0
- package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts +17 -0
- package/dist/remark-mdx-mermaid-BdSUUiCG.d.ts.map +1 -0
- package/dist/remark-npm-BIvIEKT2.d.ts +36 -0
- package/dist/remark-npm-BIvIEKT2.d.ts.map +1 -0
- package/dist/remark-steps-CHJN-rtm.d.ts +28 -0
- package/dist/remark-steps-CHJN-rtm.d.ts.map +1 -0
- package/dist/remark-structure-RZD2gGKp.d.ts +77 -0
- package/dist/remark-structure-RZD2gGKp.d.ts.map +1 -0
- package/dist/remove-undefined-Cfs4o_mM.js +19 -0
- package/dist/remove-undefined-Cfs4o_mM.js.map +1 -0
- package/dist/search/algolia.d.ts +3 -69
- package/dist/search/algolia.js +69 -63
- package/dist/search/algolia.js.map +1 -0
- package/dist/search/client.d.ts +120 -114
- package/dist/search/client.d.ts.map +1 -0
- package/dist/search/client.js +92 -91
- package/dist/search/client.js.map +1 -0
- package/dist/search/index.d.ts +20 -18
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +3 -7
- package/dist/search/orama-cloud.d.ts +70 -68
- package/dist/search/orama-cloud.d.ts.map +1 -0
- package/dist/search/orama-cloud.js +46 -54
- package/dist/search/orama-cloud.js.map +1 -0
- package/dist/search/server.d.ts +6 -136
- package/dist/search/server.js +292 -369
- package/dist/search/server.js.map +1 -0
- package/dist/search-D6ChCLhY.js +44 -0
- package/dist/search-D6ChCLhY.js.map +1 -0
- package/dist/server-CPR_fgkH.d.ts +133 -0
- package/dist/server-CPR_fgkH.d.ts.map +1 -0
- package/dist/shiki-4oMYwHED.js +80 -0
- package/dist/shiki-4oMYwHED.js.map +1 -0
- package/dist/shiki-CIBQys54.d.ts +33 -0
- package/dist/shiki-CIBQys54.d.ts.map +1 -0
- package/dist/source/client/index.d.ts +7 -5
- package/dist/source/client/index.d.ts.map +1 -0
- package/dist/source/client/index.js +24 -35
- package/dist/source/client/index.js.map +1 -0
- package/dist/source/index.d.ts +3 -42
- package/dist/source/index.js +599 -752
- package/dist/source/index.js.map +1 -0
- package/dist/source/plugins/lucide-icons.d.ts +7 -7
- package/dist/source/plugins/lucide-icons.d.ts.map +1 -0
- package/dist/source/plugins/lucide-icons.js +21 -20
- package/dist/source/plugins/lucide-icons.js.map +1 -0
- package/dist/source/plugins/slugs.d.ts +3 -0
- package/dist/source/plugins/slugs.js +65 -0
- package/dist/source/plugins/slugs.js.map +1 -0
- package/dist/source/schema.d.ts +17 -14
- package/dist/source/schema.d.ts.map +1 -0
- package/dist/source/schema.js +26 -22
- package/dist/source/schema.js.map +1 -0
- package/dist/static-Dq8pA8Ay.js +51 -0
- package/dist/static-Dq8pA8Ay.js.map +1 -0
- package/dist/toc.d.ts +38 -25
- package/dist/toc.d.ts.map +1 -0
- package/dist/toc.js +123 -136
- package/dist/toc.js.map +1 -0
- package/dist/util-CK2ykiif.d.ts +8 -0
- package/dist/util-CK2ykiif.d.ts.map +1 -0
- package/dist/util-s9piKHsk.js +10 -0
- package/dist/util-s9piKHsk.js.map +1 -0
- package/dist/utils/use-effect-event.d.ts +3 -1
- package/dist/utils/use-effect-event.d.ts.map +1 -0
- package/dist/utils/use-effect-event.js +16 -13
- package/dist/utils/use-effect-event.js.map +1 -0
- package/dist/utils/use-media-query.d.ts +3 -1
- package/dist/utils/use-media-query.d.ts.map +1 -0
- package/dist/utils/use-media-query.js +20 -20
- package/dist/utils/use-media-query.js.map +1 -0
- package/dist/utils/use-on-change.d.ts +3 -1
- package/dist/utils/use-on-change.d.ts.map +1 -0
- package/dist/utils/use-on-change.js +23 -7
- package/dist/utils/use-on-change.js.map +1 -0
- package/dist/utils-DUvi2WkD.js +134 -0
- package/dist/utils-DUvi2WkD.js.map +1 -0
- package/package.json +60 -58
- package/dist/algolia-IZEDLPHE.js +0 -58
- package/dist/chunk-5PMI7QDD.js +0 -220
- package/dist/chunk-ADBHPKXG.js +0 -78
- package/dist/chunk-APKPSBSB.js +0 -74
- package/dist/chunk-CH7YHH7V.js +0 -222
- package/dist/chunk-EFVXL2PP.js +0 -144
- package/dist/chunk-EMWGTXSW.js +0 -19
- package/dist/chunk-FAEPKD7U.js +0 -20
- package/dist/chunk-FUUVPEA5.js +0 -29
- package/dist/chunk-GINBKBVQ.js +0 -12
- package/dist/chunk-GLRQBLGN.js +0 -59
- package/dist/chunk-JUF4WZ6G.js +0 -117
- package/dist/chunk-K4WNLOVQ.js +0 -75
- package/dist/chunk-L4JKQWCM.js +0 -131
- package/dist/chunk-MA6O2UUE.js +0 -50
- package/dist/chunk-ONG4RVCR.js +0 -8
- package/dist/chunk-OTD7MV33.js +0 -53
- package/dist/chunk-PFNP6PEB.js +0 -11
- package/dist/chunk-SH7BNTG7.js +0 -38
- package/dist/chunk-TWIDBWFG.js +0 -84
- package/dist/chunk-U67V476Y.js +0 -35
- package/dist/chunk-VLSDGCJE.js +0 -47
- package/dist/chunk-W6WTLKRA.js +0 -73
- package/dist/chunk-X2HFD5QJ.js +0 -275
- package/dist/chunk-XJ6ZQNEX.js +0 -91
- package/dist/chunk-XN2LKXFZ.js +0 -101
- package/dist/chunk-XOFXGHS4.js +0 -93
- package/dist/chunk-XZSI7AHE.js +0 -67
- package/dist/chunk-YVVDKJ2H.js +0 -34
- package/dist/chunk-ZMWYLUDP.js +0 -21
- package/dist/definitions-pJ7PybYY.d.ts +0 -60
- package/dist/fetch-IBTWQCJR.js +0 -22
- package/dist/loader-_E2HOdV0.d.ts +0 -333
- package/dist/mixedbread-A3WLENES.js +0 -117
- package/dist/orama-cloud-UZAPMPFV.js +0 -93
- package/dist/static-A2YJ5TXV.js +0 -62
- package/dist/util-bZU2QeJ2.d.ts +0 -6
|
@@ -1,8 +1,184 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { generateCodeBlockTabs, parseCodeBlockAttributes } from "./codeblock-utils.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
|
|
4
|
+
//#region src/mdx-plugins/remark-code-tab.ts
|
|
5
|
+
const Types = {
|
|
6
|
+
CodeBlockTabs: { convert(processor, nodes, withMdx = false, withParent = true) {
|
|
7
|
+
const tabs = Array.from(processTabValue(nodes).entries());
|
|
8
|
+
const node = generateCodeBlockTabs({
|
|
9
|
+
defaultValue: tabs[0][0],
|
|
10
|
+
triggers: tabs.map(([name]) => ({
|
|
11
|
+
value: name,
|
|
12
|
+
children: [withMdx ? mdxToAst(processor, name) : {
|
|
13
|
+
type: "text",
|
|
14
|
+
value: name
|
|
15
|
+
}]
|
|
16
|
+
})),
|
|
17
|
+
tabs: tabs.map(([name, codes]) => ({
|
|
18
|
+
value: name,
|
|
19
|
+
children: codes
|
|
20
|
+
}))
|
|
21
|
+
});
|
|
22
|
+
if (!withParent) return createFragment(node.children);
|
|
23
|
+
return node;
|
|
24
|
+
} },
|
|
25
|
+
Tabs: { convert(processor, nodes, withMdx = false, withParent = true) {
|
|
26
|
+
const tabs = Array.from(processTabValue(nodes).entries());
|
|
27
|
+
if (!withMdx) {
|
|
28
|
+
const children$1 = tabs.map(([name, codes]) => {
|
|
29
|
+
return {
|
|
30
|
+
type: "mdxJsxFlowElement",
|
|
31
|
+
name: "Tab",
|
|
32
|
+
attributes: [{
|
|
33
|
+
type: "mdxJsxAttribute",
|
|
34
|
+
name: "value",
|
|
35
|
+
value: name
|
|
36
|
+
}],
|
|
37
|
+
children: codes
|
|
38
|
+
};
|
|
39
|
+
});
|
|
40
|
+
if (!withParent) return createFragment(children$1);
|
|
41
|
+
return {
|
|
42
|
+
type: "mdxJsxFlowElement",
|
|
43
|
+
name: "Tabs",
|
|
44
|
+
attributes: [{
|
|
45
|
+
type: "mdxJsxAttribute",
|
|
46
|
+
name: "items",
|
|
47
|
+
value: {
|
|
48
|
+
type: "mdxJsxAttributeValueExpression",
|
|
49
|
+
value: tabs.map(([name]) => name).join(", "),
|
|
50
|
+
data: { estree: {
|
|
51
|
+
type: "Program",
|
|
52
|
+
sourceType: "module",
|
|
53
|
+
comments: [],
|
|
54
|
+
body: [{
|
|
55
|
+
type: "ExpressionStatement",
|
|
56
|
+
expression: {
|
|
57
|
+
type: "ArrayExpression",
|
|
58
|
+
elements: tabs.map(([name]) => ({
|
|
59
|
+
type: "Literal",
|
|
60
|
+
value: name
|
|
61
|
+
}))
|
|
62
|
+
}
|
|
63
|
+
}]
|
|
64
|
+
} }
|
|
65
|
+
}
|
|
66
|
+
}],
|
|
67
|
+
children: children$1
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
const children = [{
|
|
71
|
+
type: "mdxJsxFlowElement",
|
|
72
|
+
name: "TabsList",
|
|
73
|
+
attributes: [],
|
|
74
|
+
children: tabs.map(([name]) => ({
|
|
75
|
+
type: "mdxJsxFlowElement",
|
|
76
|
+
name: "TabsTrigger",
|
|
77
|
+
attributes: [{
|
|
78
|
+
type: "mdxJsxAttribute",
|
|
79
|
+
name: "value",
|
|
80
|
+
value: name
|
|
81
|
+
}],
|
|
82
|
+
children: [mdxToAst(processor, name)]
|
|
83
|
+
}))
|
|
84
|
+
}, ...tabs.map(([name, codes]) => ({
|
|
85
|
+
type: "mdxJsxFlowElement",
|
|
86
|
+
name: "TabsContent",
|
|
87
|
+
attributes: [{
|
|
88
|
+
type: "mdxJsxAttribute",
|
|
89
|
+
name: "value",
|
|
90
|
+
value: name
|
|
91
|
+
}],
|
|
92
|
+
children: codes
|
|
93
|
+
}))];
|
|
94
|
+
if (!withParent) return createFragment(children);
|
|
95
|
+
return {
|
|
96
|
+
type: "mdxJsxFlowElement",
|
|
97
|
+
name: "Tabs",
|
|
98
|
+
attributes: [{
|
|
99
|
+
type: "mdxJsxAttribute",
|
|
100
|
+
name: "defaultValue",
|
|
101
|
+
value: tabs[0][0]
|
|
102
|
+
}],
|
|
103
|
+
children
|
|
104
|
+
};
|
|
105
|
+
} }
|
|
8
106
|
};
|
|
107
|
+
function remarkCodeTab(options = {}) {
|
|
108
|
+
const { parseMdx = false, Tabs = "CodeBlockTabs" } = options;
|
|
109
|
+
return (tree) => {
|
|
110
|
+
const ignored = /* @__PURE__ */ new WeakSet();
|
|
111
|
+
visit(tree, (node) => {
|
|
112
|
+
if (!("children" in node) || ignored.has(node)) return "skip";
|
|
113
|
+
let localTabs = Tabs;
|
|
114
|
+
let localParseMdx = parseMdx;
|
|
115
|
+
let withParent = true;
|
|
116
|
+
if (node.type === "mdxJsxFlowElement" && node.name && node.name in Types) {
|
|
117
|
+
withParent = false;
|
|
118
|
+
localTabs = node.name;
|
|
119
|
+
if (node.name === "Tabs" && localParseMdx) localParseMdx = node.attributes.every((attribute) => attribute.type !== "mdxJsxAttribute" || attribute.name !== "items");
|
|
120
|
+
}
|
|
121
|
+
let start = -1;
|
|
122
|
+
let end = 0;
|
|
123
|
+
const close = () => {
|
|
124
|
+
if (start === -1 || start === end) return;
|
|
125
|
+
const replacement = Types[localTabs].convert(this, node.children.slice(start, end), localParseMdx, withParent);
|
|
126
|
+
ignored.add(replacement);
|
|
127
|
+
node.children.splice(start, end - start, replacement);
|
|
128
|
+
end = start;
|
|
129
|
+
start = -1;
|
|
130
|
+
};
|
|
131
|
+
for (; end < node.children.length; end++) {
|
|
132
|
+
const child = node.children[end];
|
|
133
|
+
if (child.type !== "code" || !child.meta) {
|
|
134
|
+
close();
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
const meta = parseCodeBlockAttributes(child.meta, ["tab"]);
|
|
138
|
+
if (!meta.attributes.tab) {
|
|
139
|
+
close();
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
if (start === -1) start = end;
|
|
143
|
+
child.meta = meta.rest;
|
|
144
|
+
child.data ??= {};
|
|
145
|
+
child.data.tab = meta.attributes.tab;
|
|
146
|
+
}
|
|
147
|
+
close();
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function processTabValue(nodes) {
|
|
152
|
+
const out = /* @__PURE__ */ new Map();
|
|
153
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
154
|
+
const node = nodes[i];
|
|
155
|
+
const name = node.data?.tab ?? `Tab ${i + 1}`;
|
|
156
|
+
const li = out.get(name) ?? [];
|
|
157
|
+
li.push(node);
|
|
158
|
+
out.set(name, li);
|
|
159
|
+
}
|
|
160
|
+
return out;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* MDX tab name to tab trigger node children
|
|
164
|
+
*/
|
|
165
|
+
function mdxToAst(processor, name) {
|
|
166
|
+
const node = processor.parse(name);
|
|
167
|
+
if (node.type === "root") node.children = node.children.flatMap((child) => {
|
|
168
|
+
if (child.type === "paragraph") return child.children;
|
|
169
|
+
return child;
|
|
170
|
+
});
|
|
171
|
+
return node;
|
|
172
|
+
}
|
|
173
|
+
function createFragment(children) {
|
|
174
|
+
return {
|
|
175
|
+
type: "mdxJsxFlowElement",
|
|
176
|
+
name: null,
|
|
177
|
+
attributes: [],
|
|
178
|
+
children
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
//#endregion
|
|
183
|
+
export { remarkCodeTab };
|
|
184
|
+
//# sourceMappingURL=remark-code-tab.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-code-tab.js","names":["children: MdxJsxFlowElement[]","children","localTabs: TabType"],"sources":["../../src/mdx-plugins/remark-code-tab.ts"],"sourcesContent":["import type { Processor, Transformer } from 'unified';\nimport type { BlockContent, Code, DefinitionContent, Root } from 'mdast';\nimport { visit } from 'unist-util-visit';\nimport type { MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { generateCodeBlockTabs, parseCodeBlockAttributes } from '@/mdx-plugins/codeblock-utils';\n\ntype TabType = keyof typeof Types;\nexport interface RemarkCodeTabOptions {\n Tabs?: TabType;\n\n /**\n * Parse MDX in tab values\n *\n * @defaultValue false\n */\n parseMdx?: boolean;\n}\n\ndeclare module 'mdast' {\n export interface CodeData {\n tab?: string;\n }\n}\n\nconst Tabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n if (!withMdx) {\n const children: MdxJsxFlowElement[] = tabs.map(([name, codes]) => {\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tab',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n };\n });\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'items',\n value: {\n type: 'mdxJsxAttributeValueExpression',\n value: tabs.map(([name]) => name).join(', '),\n data: {\n estree: {\n type: 'Program',\n sourceType: 'module',\n comments: [],\n body: [\n {\n type: 'ExpressionStatement',\n expression: {\n type: 'ArrayExpression',\n elements: tabs.map(([name]) => ({\n type: 'Literal',\n value: name,\n })),\n },\n },\n ],\n },\n },\n },\n },\n ],\n children,\n };\n }\n\n const children: MdxJsxFlowElement[] = [\n {\n type: 'mdxJsxFlowElement',\n name: 'TabsList',\n attributes: [],\n children: tabs.map(([name]) => ({\n type: 'mdxJsxFlowElement',\n name: 'TabsTrigger',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: [mdxToAst(processor, name) as unknown as BlockContent],\n })),\n },\n ...tabs.map(\n ([name, codes]) =>\n ({\n type: 'mdxJsxFlowElement',\n name: 'TabsContent',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'value',\n value: name,\n },\n ],\n children: codes,\n }) as MdxJsxFlowElement,\n ),\n ];\n\n if (!withParent) return createFragment(children);\n\n return {\n type: 'mdxJsxFlowElement',\n name: 'Tabs',\n attributes: [\n {\n type: 'mdxJsxAttribute',\n name: 'defaultValue',\n value: tabs[0][0],\n },\n ],\n children,\n };\n },\n};\n\nconst CodeBlockTabs = {\n convert(\n processor: Processor,\n nodes: Code[],\n withMdx = false,\n withParent = true,\n ): MdxJsxFlowElement {\n const tabs = Array.from(processTabValue(nodes).entries());\n\n const node = generateCodeBlockTabs({\n defaultValue: tabs[0][0],\n triggers: tabs.map(([name]) => ({\n value: name,\n children: [\n withMdx\n ? (mdxToAst(processor, name) as unknown as BlockContent)\n : {\n type: 'text',\n value: name,\n },\n ],\n })),\n tabs: tabs.map(([name, codes]) => ({\n value: name,\n children: codes,\n })),\n });\n\n if (!withParent) return createFragment(node.children);\n return node;\n },\n};\n\nconst Types = {\n CodeBlockTabs,\n Tabs,\n};\n\nexport function remarkCodeTab(\n this: Processor,\n options: RemarkCodeTabOptions = {},\n): Transformer<Root, Root> {\n const { parseMdx = false, Tabs = 'CodeBlockTabs' } = options;\n\n return (tree) => {\n const ignored = new WeakSet();\n\n visit(tree, (node) => {\n if (!('children' in node) || ignored.has(node)) return 'skip';\n let localTabs: TabType = Tabs;\n let localParseMdx = parseMdx;\n let withParent = true;\n\n if (node.type === 'mdxJsxFlowElement' && node.name && node.name in Types) {\n withParent = false;\n localTabs = node.name as TabType;\n\n // for `Tabs` in simple mode, it doesn't support MDX tab names\n if (node.name === 'Tabs' && localParseMdx) {\n localParseMdx = node.attributes.every(\n (attribute) => attribute.type !== 'mdxJsxAttribute' || attribute.name !== 'items',\n );\n }\n }\n\n let start = -1;\n let end = 0;\n const close = () => {\n if (start === -1 || start === end) return;\n const replacement = Types[localTabs].convert(\n this,\n node.children.slice(start, end) as Code[],\n localParseMdx,\n withParent,\n );\n\n ignored.add(replacement);\n node.children.splice(start, end - start, replacement);\n end = start;\n start = -1;\n };\n\n for (; end < node.children.length; end++) {\n const child = node.children[end];\n if (child.type !== 'code' || !child.meta) {\n close();\n continue;\n }\n\n const meta = parseCodeBlockAttributes(child.meta, ['tab']);\n if (!meta.attributes.tab) {\n close();\n continue;\n }\n\n if (start === -1) start = end;\n child.meta = meta.rest;\n child.data ??= {};\n child.data.tab = meta.attributes.tab;\n }\n\n close();\n });\n };\n}\n\nfunction processTabValue(nodes: Code[]) {\n const out = new Map<string, Code[]>();\n\n for (let i = 0; i < nodes.length; i++) {\n const node = nodes[i];\n const name = node.data?.tab ?? `Tab ${i + 1}`;\n const li = out.get(name) ?? [];\n li.push(node);\n out.set(name, li);\n }\n return out;\n}\n\n/**\n * MDX tab name to tab trigger node children\n */\nfunction mdxToAst(processor: Processor, name: string) {\n const node = processor.parse(name) as Root;\n\n if (node.type === 'root') {\n node.children = node.children.flatMap((child) => {\n if (child.type === 'paragraph') return child.children;\n\n return child;\n });\n }\n\n return node;\n}\n\nfunction createFragment(children: (BlockContent | DefinitionContent)[]): MdxJsxFlowElement {\n return {\n type: 'mdxJsxFlowElement',\n name: null,\n attributes: [],\n children,\n };\n}\n"],"mappings":"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"}
|
|
@@ -1,27 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface RemarkDirectiveAdmonitionOptions {
|
|
5
|
-
/**
|
|
6
|
-
* the tag names of Callout component.
|
|
7
|
-
*/
|
|
8
|
-
tags?: {
|
|
9
|
-
CalloutContainer?: string;
|
|
10
|
-
CalloutTitle?: string;
|
|
11
|
-
CalloutDescription?: string;
|
|
12
|
-
};
|
|
13
|
-
/**
|
|
14
|
-
* All supported admonition types and their linked Callout type.
|
|
15
|
-
*
|
|
16
|
-
* When specified, all defaults will be cleared.
|
|
17
|
-
*/
|
|
18
|
-
types?: Record<string, string>;
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.
|
|
22
|
-
*
|
|
23
|
-
* Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.
|
|
24
|
-
*/
|
|
25
|
-
declare function remarkDirectiveAdmonition({ tags: { CalloutContainer, CalloutTitle, CalloutDescription, }, types, }?: RemarkDirectiveAdmonitionOptions): Transformer<Root, Root>;
|
|
26
|
-
|
|
27
|
-
export { type RemarkDirectiveAdmonitionOptions, remarkDirectiveAdmonition };
|
|
1
|
+
import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-BCm_yiU9.js";
|
|
2
|
+
export { RemarkDirectiveAdmonitionOptions, remarkDirectiveAdmonition };
|
|
@@ -1,7 +1,60 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
|
|
3
|
+
//#region src/mdx-plugins/remark-directive-admonition.ts
|
|
4
|
+
/**
|
|
5
|
+
* Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.
|
|
6
|
+
*
|
|
7
|
+
* Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.
|
|
8
|
+
*/
|
|
9
|
+
function remarkDirectiveAdmonition({ tags: { CalloutContainer = "CalloutContainer", CalloutTitle = "CalloutTitle", CalloutDescription = "CalloutDescription" } = {}, types = {
|
|
10
|
+
note: "info",
|
|
11
|
+
tip: "info",
|
|
12
|
+
info: "info",
|
|
13
|
+
warn: "warning",
|
|
14
|
+
warning: "warning",
|
|
15
|
+
danger: "error",
|
|
16
|
+
success: "success"
|
|
17
|
+
} } = {}) {
|
|
18
|
+
return (tree) => {
|
|
19
|
+
visit(tree, "containerDirective", (node) => {
|
|
20
|
+
if (!(node.name in types)) return;
|
|
21
|
+
const attributes = [{
|
|
22
|
+
type: "mdxJsxAttribute",
|
|
23
|
+
name: "type",
|
|
24
|
+
value: types[node.name]
|
|
25
|
+
}];
|
|
26
|
+
for (const [k, v] of Object.entries(node.attributes ?? {})) attributes.push({
|
|
27
|
+
type: "mdxJsxAttribute",
|
|
28
|
+
name: k,
|
|
29
|
+
value: v
|
|
30
|
+
});
|
|
31
|
+
const titleNodes = [];
|
|
32
|
+
const descriptionNodes = [];
|
|
33
|
+
for (const item of node.children) if (item.type === "paragraph" && item.data?.directiveLabel) titleNodes.push(...item.children);
|
|
34
|
+
else descriptionNodes.push(item);
|
|
35
|
+
const children = [];
|
|
36
|
+
if (titleNodes.length > 0) children.push({
|
|
37
|
+
type: "mdxJsxFlowElement",
|
|
38
|
+
name: CalloutTitle,
|
|
39
|
+
attributes: [],
|
|
40
|
+
children: titleNodes
|
|
41
|
+
});
|
|
42
|
+
if (descriptionNodes.length > 0) children.push({
|
|
43
|
+
type: "mdxJsxFlowElement",
|
|
44
|
+
name: CalloutDescription,
|
|
45
|
+
attributes: [],
|
|
46
|
+
children: descriptionNodes
|
|
47
|
+
});
|
|
48
|
+
Object.assign(node, {
|
|
49
|
+
type: "mdxJsxFlowElement",
|
|
50
|
+
attributes,
|
|
51
|
+
name: CalloutContainer,
|
|
52
|
+
children
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
//#endregion
|
|
59
|
+
export { remarkDirectiveAdmonition };
|
|
60
|
+
//# sourceMappingURL=remark-directive-admonition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-directive-admonition.js","names":["attributes: MdxJsxAttribute[]","titleNodes: PhrasingContent[]","descriptionNodes: (BlockContent | DefinitionContent)[]","children: MdxJsxFlowElement[]"],"sources":["../../src/mdx-plugins/remark-directive-admonition.ts"],"sourcesContent":["import type { BlockContent, DefinitionContent, PhrasingContent, Root } from 'mdast';\nimport type { MdxJsxAttribute, MdxJsxFlowElement } from 'mdast-util-mdx-jsx';\nimport { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\n\nexport interface RemarkDirectiveAdmonitionOptions {\n /**\n * the tag names of Callout component.\n */\n tags?: {\n CalloutContainer?: string;\n CalloutTitle?: string;\n CalloutDescription?: string;\n };\n\n /**\n * All supported admonition types and their linked Callout type.\n *\n * When specified, all defaults will be cleared.\n */\n types?: Record<string, string>;\n}\n\n/**\n * Remark Plugin to support Admonition syntax in Docusaurus, useful for migrating from Docusaurus.\n *\n * Requires [`remark-directive`](https://github.com/remarkjs/remark-directive) to be configured.\n */\nexport function remarkDirectiveAdmonition({\n tags: {\n CalloutContainer = 'CalloutContainer',\n CalloutTitle = 'CalloutTitle',\n CalloutDescription = 'CalloutDescription',\n } = {},\n types = {\n note: 'info',\n tip: 'info',\n info: 'info',\n warn: 'warning',\n warning: 'warning',\n danger: 'error',\n success: 'success',\n },\n}: RemarkDirectiveAdmonitionOptions = {}): Transformer<Root, Root> {\n return (tree) => {\n visit(tree, 'containerDirective', (node) => {\n if (!(node.name in types)) return;\n\n const attributes: MdxJsxAttribute[] = [\n {\n type: 'mdxJsxAttribute',\n name: 'type',\n value: types[node.name],\n },\n ];\n\n for (const [k, v] of Object.entries(node.attributes ?? {})) {\n attributes.push({\n type: 'mdxJsxAttribute',\n name: k,\n value: v,\n });\n }\n\n const titleNodes: PhrasingContent[] = [];\n const descriptionNodes: (BlockContent | DefinitionContent)[] = [];\n\n for (const item of node.children) {\n if (item.type === 'paragraph' && item.data?.directiveLabel) {\n titleNodes.push(...item.children);\n } else {\n descriptionNodes.push(item);\n }\n }\n\n const children: MdxJsxFlowElement[] = [];\n\n if (titleNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutTitle,\n attributes: [],\n children: titleNodes as BlockContent[],\n });\n }\n\n if (descriptionNodes.length > 0) {\n children.push({\n type: 'mdxJsxFlowElement',\n name: CalloutDescription,\n attributes: [],\n children: descriptionNodes,\n });\n }\n\n Object.assign(node, {\n type: 'mdxJsxFlowElement',\n attributes,\n name: CalloutContainer,\n children,\n } satisfies MdxJsxFlowElement);\n });\n };\n}\n"],"mappings":";;;;;;;;AA4BA,SAAgB,0BAA0B,EACxC,MAAM,EACJ,mBAAmB,oBACnB,eAAe,gBACf,qBAAqB,yBACnB,EAAE,EACN,QAAQ;CACN,MAAM;CACN,KAAK;CACL,MAAM;CACN,MAAM;CACN,SAAS;CACT,QAAQ;CACR,SAAS;CACV,KACmC,EAAE,EAA2B;AACjE,SAAQ,SAAS;AACf,QAAM,MAAM,uBAAuB,SAAS;AAC1C,OAAI,EAAE,KAAK,QAAQ,OAAQ;GAE3B,MAAMA,aAAgC,CACpC;IACE,MAAM;IACN,MAAM;IACN,OAAO,MAAM,KAAK;IACnB,CACF;AAED,QAAK,MAAM,CAAC,GAAG,MAAM,OAAO,QAAQ,KAAK,cAAc,EAAE,CAAC,CACxD,YAAW,KAAK;IACd,MAAM;IACN,MAAM;IACN,OAAO;IACR,CAAC;GAGJ,MAAMC,aAAgC,EAAE;GACxC,MAAMC,mBAAyD,EAAE;AAEjE,QAAK,MAAM,QAAQ,KAAK,SACtB,KAAI,KAAK,SAAS,eAAe,KAAK,MAAM,eAC1C,YAAW,KAAK,GAAG,KAAK,SAAS;OAEjC,kBAAiB,KAAK,KAAK;GAI/B,MAAMC,WAAgC,EAAE;AAExC,OAAI,WAAW,SAAS,EACtB,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,OAAI,iBAAiB,SAAS,EAC5B,UAAS,KAAK;IACZ,MAAM;IACN,MAAM;IACN,YAAY,EAAE;IACd,UAAU;IACX,CAAC;AAGJ,UAAO,OAAO,MAAM;IAClB,MAAM;IACN;IACA,MAAM;IACN;IACD,CAA6B;IAC9B"}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-CeWpMwyk.js";
|
|
2
|
+
export { RemarkGfmOptions, remarkGfm };
|
|
@@ -1,31 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
declare module 'mdast' {
|
|
5
|
-
interface HeadingData extends Data {
|
|
6
|
-
hProperties?: {
|
|
7
|
-
id?: string;
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
interface RemarkHeadingOptions {
|
|
12
|
-
slug?: (root: Root, heading: Heading, text: string) => string;
|
|
13
|
-
/**
|
|
14
|
-
* Allow custom headings ids
|
|
15
|
-
*
|
|
16
|
-
* @defaultValue true
|
|
17
|
-
*/
|
|
18
|
-
customId?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
* Attach an array of `TOCItemType` to `file.data.toc`
|
|
21
|
-
*
|
|
22
|
-
* @defaultValue true
|
|
23
|
-
*/
|
|
24
|
-
generateToc?: boolean;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Add heading ids and extract TOC
|
|
28
|
-
*/
|
|
29
|
-
declare function remarkHeading({ slug: defaultSlug, customId, generateToc, }?: RemarkHeadingOptions): Transformer<Root, Root>;
|
|
30
|
-
|
|
31
|
-
export { type RemarkHeadingOptions, remarkHeading };
|
|
1
|
+
import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-CXvCY0go.js";
|
|
2
|
+
export { RemarkHeadingOptions, remarkHeading };
|
|
@@ -1,8 +1,45 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { t as flattenNode } from "../mdast-utils-mc9-X-PK.js";
|
|
2
|
+
import Slugger from "github-slugger";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
|
+
|
|
5
|
+
//#region src/mdx-plugins/remark-heading.ts
|
|
6
|
+
const slugger = new Slugger();
|
|
7
|
+
const regex = /\s*\[#(?<slug>[^]+?)]\s*$/;
|
|
8
|
+
/**
|
|
9
|
+
* Add heading ids and extract TOC
|
|
10
|
+
*/
|
|
11
|
+
function remarkHeading({ slug: defaultSlug, customId = true, generateToc = true } = {}) {
|
|
12
|
+
return (root, file) => {
|
|
13
|
+
const toc = [];
|
|
14
|
+
slugger.reset();
|
|
15
|
+
visit(root, "heading", (heading) => {
|
|
16
|
+
heading.data ||= {};
|
|
17
|
+
heading.data.hProperties ||= {};
|
|
18
|
+
const props = heading.data.hProperties;
|
|
19
|
+
const lastNode = heading.children.at(-1);
|
|
20
|
+
if (lastNode?.type === "text" && customId) {
|
|
21
|
+
const match = regex.exec(lastNode.value);
|
|
22
|
+
if (match?.[1]) {
|
|
23
|
+
props.id = match[1];
|
|
24
|
+
lastNode.value = lastNode.value.slice(0, match.index);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
let flattened = null;
|
|
28
|
+
if (!props.id) {
|
|
29
|
+
flattened ??= flattenNode(heading);
|
|
30
|
+
props.id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);
|
|
31
|
+
}
|
|
32
|
+
if (generateToc) toc.push({
|
|
33
|
+
title: flattened ?? flattenNode(heading),
|
|
34
|
+
url: `#${props.id}`,
|
|
35
|
+
depth: heading.depth
|
|
36
|
+
});
|
|
37
|
+
return "skip";
|
|
38
|
+
});
|
|
39
|
+
if (generateToc) file.data.toc = toc;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
//#endregion
|
|
44
|
+
export { remarkHeading };
|
|
45
|
+
//# sourceMappingURL=remark-heading.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-heading.js","names":["toc: TOCItemType[]","flattened: string | null"],"sources":["../../src/mdx-plugins/remark-heading.ts"],"sourcesContent":["import Slugger from 'github-slugger';\nimport type { Heading, Root } from 'mdast';\nimport type { Transformer } from 'unified';\nimport { visit } from 'unist-util-visit';\nimport type { TOCItemType } from '@/toc';\nimport { flattenNode } from '@/mdx-plugins/mdast-utils';\n\nconst slugger = new Slugger();\n\ndeclare module 'mdast' {\n export interface HeadingData extends Data {\n hProperties?: {\n id?: string;\n };\n }\n}\n\nconst regex = /\\s*\\[#(?<slug>[^]+?)]\\s*$/;\n\nexport interface RemarkHeadingOptions {\n slug?: (root: Root, heading: Heading, text: string) => string;\n\n /**\n * Allow custom headings ids\n *\n * @defaultValue true\n */\n customId?: boolean;\n\n /**\n * Attach an array of `TOCItemType` to `file.data.toc`\n *\n * @defaultValue true\n */\n generateToc?: boolean;\n}\n\n/**\n * Add heading ids and extract TOC\n */\nexport function remarkHeading({\n slug: defaultSlug,\n customId = true,\n generateToc = true,\n}: RemarkHeadingOptions = {}): Transformer<Root, Root> {\n return (root, file) => {\n const toc: TOCItemType[] = [];\n slugger.reset();\n\n visit(root, 'heading', (heading) => {\n heading.data ||= {};\n heading.data.hProperties ||= {};\n const props = heading.data.hProperties;\n\n const lastNode = heading.children.at(-1);\n if (lastNode?.type === 'text' && customId) {\n const match = regex.exec(lastNode.value);\n\n if (match?.[1]) {\n props.id = match[1];\n lastNode.value = lastNode.value.slice(0, match.index);\n }\n }\n\n let flattened: string | null = null;\n if (!props.id) {\n flattened ??= flattenNode(heading);\n\n props.id = defaultSlug ? defaultSlug(root, heading, flattened) : slugger.slug(flattened);\n }\n\n if (generateToc) {\n toc.push({\n title: flattened ?? flattenNode(heading),\n url: `#${props.id}`,\n depth: heading.depth,\n });\n }\n\n return 'skip';\n });\n\n if (generateToc) file.data.toc = toc;\n };\n}\n"],"mappings":";;;;;AAOA,MAAM,UAAU,IAAI,SAAS;AAU7B,MAAM,QAAQ;;;;AAuBd,SAAgB,cAAc,EAC5B,MAAM,aACN,WAAW,MACX,cAAc,SACU,EAAE,EAA2B;AACrD,SAAQ,MAAM,SAAS;EACrB,MAAMA,MAAqB,EAAE;AAC7B,UAAQ,OAAO;AAEf,QAAM,MAAM,YAAY,YAAY;AAClC,WAAQ,SAAS,EAAE;AACnB,WAAQ,KAAK,gBAAgB,EAAE;GAC/B,MAAM,QAAQ,QAAQ,KAAK;GAE3B,MAAM,WAAW,QAAQ,SAAS,GAAG,GAAG;AACxC,OAAI,UAAU,SAAS,UAAU,UAAU;IACzC,MAAM,QAAQ,MAAM,KAAK,SAAS,MAAM;AAExC,QAAI,QAAQ,IAAI;AACd,WAAM,KAAK,MAAM;AACjB,cAAS,QAAQ,SAAS,MAAM,MAAM,GAAG,MAAM,MAAM;;;GAIzD,IAAIC,YAA2B;AAC/B,OAAI,CAAC,MAAM,IAAI;AACb,kBAAc,YAAY,QAAQ;AAElC,UAAM,KAAK,cAAc,YAAY,MAAM,SAAS,UAAU,GAAG,QAAQ,KAAK,UAAU;;AAG1F,OAAI,YACF,KAAI,KAAK;IACP,OAAO,aAAa,YAAY,QAAQ;IACxC,KAAK,IAAI,MAAM;IACf,OAAO,QAAQ;IAChB,CAAC;AAGJ,UAAO;IACP;AAEF,MAAI,YAAa,MAAK,KAAK,MAAM"}
|
|
@@ -1,57 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type ExternalImageOptions = {
|
|
5
|
-
/**
|
|
6
|
-
* timeout for fetching remote images (in milliseconds)
|
|
7
|
-
*/
|
|
8
|
-
timeout?: number;
|
|
9
|
-
} | boolean;
|
|
10
|
-
interface RemarkImageOptions {
|
|
11
|
-
/**
|
|
12
|
-
* Directory or base URL to resolve absolute image paths
|
|
13
|
-
*/
|
|
14
|
-
publicDir?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Preferred placeholder type, only available with `useImport` + local images.
|
|
17
|
-
*
|
|
18
|
-
* @defaultValue 'blur'
|
|
19
|
-
*/
|
|
20
|
-
placeholder?: 'blur' | 'none';
|
|
21
|
-
/**
|
|
22
|
-
* Define how to handle errors when fetching image size.
|
|
23
|
-
*
|
|
24
|
-
* - `error` (default): throw an error.
|
|
25
|
-
* - `ignore`: do absolutely nothing (Next.js Image component may complain).
|
|
26
|
-
* - `hide`: remove that image element.
|
|
27
|
-
*
|
|
28
|
-
* @defaultValue 'error'
|
|
29
|
-
*/
|
|
30
|
-
onError?: 'error' | 'hide' | 'ignore' | ((error: Error) => void);
|
|
31
|
-
/**
|
|
32
|
-
* Import images in the file, and let bundlers handle it.
|
|
33
|
-
*
|
|
34
|
-
* ```tsx
|
|
35
|
-
* import MyImage from "./public/img.png";
|
|
36
|
-
*
|
|
37
|
-
* <img src={MyImage} />
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* When disabled, `placeholder` will be ignored.
|
|
41
|
-
*
|
|
42
|
-
* @defaultValue true
|
|
43
|
-
*/
|
|
44
|
-
useImport?: boolean;
|
|
45
|
-
/**
|
|
46
|
-
* Fetch image size of external URLs
|
|
47
|
-
*
|
|
48
|
-
* @defaultValue true
|
|
49
|
-
*/
|
|
50
|
-
external?: ExternalImageOptions;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Turn images into Next.js Image compatible usage.
|
|
54
|
-
*/
|
|
55
|
-
declare function remarkImage({ placeholder, external, useImport, onError, publicDir, }?: RemarkImageOptions): Transformer<Root, Root>;
|
|
56
|
-
|
|
57
|
-
export { type RemarkImageOptions, remarkImage };
|
|
1
|
+
import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-CvUis4R1.js";
|
|
2
|
+
export { RemarkImageOptions, remarkImage };
|