@vezham/docs-core 1.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/LICENSE +21 -0
- package/README.md +5 -0
- package/dist/advanced-Ct13khZr.js +79 -0
- package/dist/algolia-C0E5qQhM.d.ts +66 -0
- package/dist/breadcrumb.d.ts +46 -0
- package/dist/breadcrumb.js +59 -0
- package/dist/build-doc-4OvfjVN2.js +85 -0
- package/dist/client-kQ39Ub0-.d.ts +247 -0
- package/dist/codeblock-utils-CyP8qsYv.d.ts +29 -0
- package/dist/content/github.d.ts +41 -0
- package/dist/content/github.js +28 -0
- package/dist/content/md/frontmatter.d.ts +15 -0
- package/dist/content/md/frontmatter.js +24 -0
- package/dist/content/md.d.ts +24 -0
- package/dist/content/md.js +43 -0
- package/dist/content/mdx/preset-bundler.d.ts +29 -0
- package/dist/content/mdx/preset-bundler.js +39 -0
- package/dist/content/mdx/preset-runtime.d.ts +26 -0
- package/dist/content/mdx/preset-runtime.js +36 -0
- package/dist/content/toc.d.ts +19 -0
- package/dist/content/toc.js +14 -0
- package/dist/definitions-CFOhwE1k.d.ts +72 -0
- package/dist/dynamic-CTsodhTH.js +905 -0
- package/dist/dynamic-link.d.ts +12 -0
- package/dist/dynamic-link.js +31 -0
- package/dist/endpoint-MyoBU5IC.js +28 -0
- package/dist/framework/astro.d.ts +21 -0
- package/dist/framework/astro.js +52 -0
- package/dist/framework/index.d.ts +40 -0
- package/dist/framework/index.js +66 -0
- package/dist/framework/next.d.ts +10 -0
- package/dist/framework/next.js +19 -0
- package/dist/framework/react-router.d.ts +10 -0
- package/dist/framework/react-router.js +43 -0
- package/dist/framework/tanstack.d.ts +13 -0
- package/dist/framework/tanstack.js +54 -0
- package/dist/framework/waku.d.ts +10 -0
- package/dist/framework/waku.js +46 -0
- package/dist/highlight/client.d.ts +11 -0
- package/dist/highlight/client.js +15 -0
- package/dist/highlight/index.d.ts +31 -0
- package/dist/highlight/index.js +30 -0
- package/dist/highlight/shiki/full.d.ts +7 -0
- package/dist/highlight/shiki/full.js +23 -0
- package/dist/highlight/shiki/index.d.ts +2 -0
- package/dist/highlight/shiki/index.js +27 -0
- package/dist/highlight/shiki/react.d.ts +23 -0
- package/dist/highlight/shiki/react.js +50 -0
- package/dist/i18n/index.d.ts +2 -0
- package/dist/i18n/index.js +63 -0
- package/dist/i18n/middleware.d.ts +34 -0
- package/dist/i18n/middleware.js +3855 -0
- package/dist/icon-BILaoXeg.js +17 -0
- package/dist/index-B-0R0VbS.d.ts +18 -0
- package/dist/index-BM36H-xw.d.ts +36 -0
- package/dist/index-BMEUQz-F.d.ts +21 -0
- package/dist/index-DAYtLGbx.d.ts +16 -0
- package/dist/index-DIwKCYOz.d.ts +513 -0
- package/dist/index-DydiXvgS.d.ts +90 -0
- package/dist/index-E8Qh_yQs.d.ts +49 -0
- package/dist/is-equal-LdLqRs0o.js +8 -0
- package/dist/link.d.ts +17 -0
- package/dist/link.js +23 -0
- package/dist/mdx-plugins/codeblock-utils.d.ts +2 -0
- package/dist/mdx-plugins/codeblock-utils.js +68 -0
- package/dist/mdx-plugins/index.d.ts +20 -0
- package/dist/mdx-plugins/index.js +18 -0
- package/dist/mdx-plugins/rehype-code.core.d.ts +3 -0
- package/dist/mdx-plugins/rehype-code.core.js +3 -0
- package/dist/mdx-plugins/rehype-code.d.ts +4 -0
- package/dist/mdx-plugins/rehype-code.js +24 -0
- package/dist/mdx-plugins/rehype-toc.d.ts +2 -0
- package/dist/mdx-plugins/rehype-toc.js +139 -0
- package/dist/mdx-plugins/remark-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-admonition.js +71 -0
- package/dist/mdx-plugins/remark-block-id.d.ts +37 -0
- package/dist/mdx-plugins/remark-block-id.js +41 -0
- package/dist/mdx-plugins/remark-code-tab.d.ts +2 -0
- package/dist/mdx-plugins/remark-code-tab.js +190 -0
- package/dist/mdx-plugins/remark-directive-admonition.d.ts +2 -0
- package/dist/mdx-plugins/remark-directive-admonition.js +57 -0
- package/dist/mdx-plugins/remark-feedback-block.d.ts +2 -0
- package/dist/mdx-plugins/remark-feedback-block.js +54 -0
- package/dist/mdx-plugins/remark-gfm.d.ts +2 -0
- package/dist/mdx-plugins/remark-gfm.js +2 -0
- package/dist/mdx-plugins/remark-heading.d.ts +2 -0
- package/dist/mdx-plugins/remark-heading.js +46 -0
- package/dist/mdx-plugins/remark-image.d.ts +2 -0
- package/dist/mdx-plugins/remark-image.js +167 -0
- package/dist/mdx-plugins/remark-llms.d.ts +2 -0
- package/dist/mdx-plugins/remark-llms.js +338 -0
- package/dist/mdx-plugins/remark-llms.runtime.d.ts +10 -0
- package/dist/mdx-plugins/remark-llms.runtime.js +24 -0
- package/dist/mdx-plugins/remark-mdx-files.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-files.js +182 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.d.ts +2 -0
- package/dist/mdx-plugins/remark-mdx-mermaid.js +28 -0
- package/dist/mdx-plugins/remark-npm.d.ts +2 -0
- package/dist/mdx-plugins/remark-npm.js +76 -0
- package/dist/mdx-plugins/remark-steps.d.ts +2 -0
- package/dist/mdx-plugins/remark-steps.js +93 -0
- package/dist/mdx-plugins/remark-structure.d.ts +2 -0
- package/dist/mdx-plugins/remark-structure.js +118 -0
- package/dist/mdx-plugins/stringifier.d.ts +2 -0
- package/dist/mdx-plugins/stringifier.js +91 -0
- package/dist/mdx-plugins/transformer-icon.d.ts +2 -0
- package/dist/mdx-plugins/transformer-icon.js +145 -0
- package/dist/negotiation/index.d.ts +17 -0
- package/dist/negotiation/index.js +378 -0
- package/dist/page-tree/index.d.ts +3 -0
- package/dist/page-tree/index.js +2 -0
- package/dist/path-1H5VzYiT.js +75 -0
- package/dist/rehype-code-D-RFJb9W.d.ts +14 -0
- package/dist/rehype-code.core-BUwNuchP.js +548 -0
- package/dist/rehype-code.core-BjH1uHWj.d.ts +115 -0
- package/dist/rehype-toc-K51AGb5U.d.ts +43 -0
- package/dist/remark-admonition-BwTcmI_S.d.ts +20 -0
- package/dist/remark-code-tab-DE_4bdnu.d.ts +34 -0
- package/dist/remark-directive-admonition-BLiJ5l43.d.ts +27 -0
- package/dist/remark-feedback-block-BxtINXN-.d.ts +45 -0
- package/dist/remark-gfm-DpVfAX1x.d.ts +2 -0
- package/dist/remark-heading-DEIzTkU5.d.ts +33 -0
- package/dist/remark-image-BI2S9LOb.d.ts +57 -0
- package/dist/remark-llms-bD3WvU2V.d.ts +73 -0
- package/dist/remark-mdx-files-Buvxc-sa.d.ts +54 -0
- package/dist/remark-mdx-mermaid-C1bCHHc6.d.ts +15 -0
- package/dist/remark-npm-BbpvkJaT.d.ts +31 -0
- package/dist/remark-steps-DqVEo0iq.d.ts +23 -0
- package/dist/remark-structure-CnHwvNZr.d.ts +87 -0
- package/dist/remove-markdown-DfKNMl9w.js +40 -0
- package/dist/remove-undefined-CzMSKybq.js +24 -0
- package/dist/rolldown-runtime-DC62tzP2.js +33 -0
- package/dist/search/algolia.d.ts +2 -0
- package/dist/search/algolia.js +75 -0
- package/dist/search/client/algolia.d.ts +2 -0
- package/dist/search/client/algolia.js +53 -0
- package/dist/search/client/fetch.d.ts +2 -0
- package/dist/search/client/fetch.js +28 -0
- package/dist/search/client/flexsearch-static.d.ts +2 -0
- package/dist/search/client/flexsearch-static.js +42 -0
- package/dist/search/client/mixedbread.d.ts +2 -0
- package/dist/search/client/mixedbread.js +65 -0
- package/dist/search/client/orama-cloud-legacy.d.ts +2 -0
- package/dist/search/client/orama-cloud-legacy.js +84 -0
- package/dist/search/client/orama-cloud.d.ts +2 -0
- package/dist/search/client/orama-cloud.js +86 -0
- package/dist/search/client/orama-static.d.ts +2 -0
- package/dist/search/client/orama-static.js +75 -0
- package/dist/search/client.d.ts +2 -0
- package/dist/search/client.js +97 -0
- package/dist/search/flexsearch.d.ts +56 -0
- package/dist/search/flexsearch.js +128 -0
- package/dist/search/index.d.ts +2 -0
- package/dist/search/index.js +74 -0
- package/dist/search/mixedbread.d.ts +49 -0
- package/dist/search/mixedbread.js +77 -0
- package/dist/search/orama-cloud-legacy.d.ts +75 -0
- package/dist/search/orama-cloud-legacy.js +48 -0
- package/dist/search/orama-cloud.d.ts +75 -0
- package/dist/search/orama-cloud.js +50 -0
- package/dist/search/server.d.ts +2 -0
- package/dist/search/server.js +237 -0
- package/dist/server-CCqACwlF.d.ts +165 -0
- package/dist/server.browser.d.ts +13 -0
- package/dist/server.browser.js +22 -0
- package/dist/server.d.ts +42 -0
- package/dist/server.js +398 -0
- package/dist/source/client/index.d.ts +2 -0
- package/dist/source/client/index.js +37 -0
- package/dist/source/dynamic.d.ts +2 -0
- package/dist/source/dynamic.js +2 -0
- package/dist/source/index.d.ts +2 -0
- package/dist/source/index.js +5 -0
- package/dist/source/llms.d.ts +2 -0
- package/dist/source/llms.js +74 -0
- package/dist/source/plugins/lucide-icons.d.ts +11 -0
- package/dist/source/plugins/lucide-icons.js +21 -0
- package/dist/source/plugins/slugs.d.ts +2 -0
- package/dist/source/plugins/slugs.js +75 -0
- package/dist/source/plugins/status-badges.d.ts +50 -0
- package/dist/source/plugins/status-badges.js +52 -0
- package/dist/source/schema.d.ts +30 -0
- package/dist/source/schema.js +28 -0
- package/dist/stringifier-B_QUcUyo.d.ts +63 -0
- package/dist/toc-CtW5lwA1.d.ts +64 -0
- package/dist/toc.d.ts +2 -0
- package/dist/toc.js +245 -0
- package/dist/transformer-icon-DlrneIS3.d.ts +17 -0
- package/dist/types-D89QoQR-.d.ts +4 -0
- package/dist/url-BVHvi3_K.js +29 -0
- package/dist/util-BDsqOxh3.d.ts +6 -0
- package/dist/util-DjBr9b3w.js +8 -0
- package/dist/utils/use-media-query.d.ts +4 -0
- package/dist/utils/use-media-query.js +20 -0
- package/dist/utils/use-on-change.d.ts +9 -0
- package/dist/utils/use-on-change.js +17 -0
- package/dist/utils-Bvy3V-fv.js +59 -0
- package/dist/utils-Cgs-6U-z.js +39 -0
- package/dist/utils-DEVq3cEC.js +151 -0
- package/dist/utils-Yx0IL9eW.js +48 -0
- package/package.json +251 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { i as toMdxExport } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import { defaultStringifier } from "./stringifier.js";
|
|
3
|
+
import { defaultHandlers } from "mdast-util-to-markdown";
|
|
4
|
+
//#region src/mdx-plugins/remark-llms.ts
|
|
5
|
+
/**
|
|
6
|
+
* generate `llms.txt` for markdown.
|
|
7
|
+
*/
|
|
8
|
+
function remarkLLMs({ as = "_markdown", headingIds = true, _data = false, mdxAsPlaceholder, output = "string", ...rest } = {}) {
|
|
9
|
+
const jsx = output === "function";
|
|
10
|
+
const stringifier = defaultStringifier({
|
|
11
|
+
...rest,
|
|
12
|
+
filterElement(node) {
|
|
13
|
+
switch (node.type) {
|
|
14
|
+
case "mdxjsEsm": return false;
|
|
15
|
+
default: return true;
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
stringify(node, parent, state, info, collect) {
|
|
19
|
+
if (mdxAsPlaceholder && !collect) switch (node.type) {
|
|
20
|
+
case "mdxJsxFlowElement":
|
|
21
|
+
case "mdxJsxTextElement": if (node.name && mdxAsPlaceholder.includes(node.name)) return placeholder(node, parent, state, info);
|
|
22
|
+
}
|
|
23
|
+
const custom = rest.stringify?.(node, parent, state, info, void 0);
|
|
24
|
+
if (custom) return custom;
|
|
25
|
+
if (collect) return collectJsx(node, state, info, collect);
|
|
26
|
+
},
|
|
27
|
+
handlers: {
|
|
28
|
+
heading(node, _p, state, info) {
|
|
29
|
+
const id = node.data?.hProperties?.id;
|
|
30
|
+
const defaultValue = defaultHandlers.heading(node, _p, state, info);
|
|
31
|
+
return headingIds && id ? `${defaultValue} [#${id}]` : defaultValue;
|
|
32
|
+
},
|
|
33
|
+
...rest.handlers
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
return (node, file) => {
|
|
37
|
+
if (jsx) {
|
|
38
|
+
const collect = [];
|
|
39
|
+
const text = stringifier.call(this, node, collect);
|
|
40
|
+
node.children.unshift(jsxToEstree(as, toJsxChunks(text, collect)));
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const value = stringifier.call(this, node, void 0);
|
|
44
|
+
node.children.unshift(toMdxExport(as, value));
|
|
45
|
+
if (_data) file.data.markdown = value;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Preserve AST data to render the MDX component at runtime, use `renderPlaceholder()` to render the placeholders.
|
|
50
|
+
*/
|
|
51
|
+
function placeholder(node, _parent, state, info) {
|
|
52
|
+
const attributes = {};
|
|
53
|
+
for (const attr of node.attributes) {
|
|
54
|
+
if (attr.type === "mdxJsxExpressionAttribute") continue;
|
|
55
|
+
attributes[attr.name] = attr.value;
|
|
56
|
+
}
|
|
57
|
+
return `\0${JSON.stringify({
|
|
58
|
+
name: node.name,
|
|
59
|
+
children: state.containerPhrasing(node, info),
|
|
60
|
+
attributes
|
|
61
|
+
})}\0`;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* `stringify` branch for the `function` output: collect the element and return a marker,
|
|
65
|
+
* resolved later by `toJsxChunks()`. Only components (capitalized names) are kept.
|
|
66
|
+
*/
|
|
67
|
+
function collectJsx(node, state, info, collect) {
|
|
68
|
+
switch (node.type) {
|
|
69
|
+
case "mdxJsxFlowElement":
|
|
70
|
+
case "mdxJsxTextElement": {
|
|
71
|
+
if (!node.name || !/^[A-Z][\w$]*$/.test(node.name)) return;
|
|
72
|
+
const entry = {
|
|
73
|
+
node,
|
|
74
|
+
children: ""
|
|
75
|
+
};
|
|
76
|
+
const marker = `\0${collect.push(entry) - 1}\0`;
|
|
77
|
+
entry.children = node.type === "mdxJsxTextElement" ? state.containerPhrasing(node, info) : state.containerFlow(node, info);
|
|
78
|
+
return marker;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const Marker = /\0(\d+)\0/g;
|
|
83
|
+
/**
|
|
84
|
+
* Split stringified Markdown on the markers emitted by `collectJsx()` into
|
|
85
|
+
* alternating text chunks and kept JSX elements, recursively for their children.
|
|
86
|
+
*/
|
|
87
|
+
function toJsxChunks(text, collect) {
|
|
88
|
+
const out = [];
|
|
89
|
+
let idx = 0;
|
|
90
|
+
for (const match of text.matchAll(Marker)) {
|
|
91
|
+
if (match.index > idx) out.push(text.slice(idx, match.index));
|
|
92
|
+
const { node, children } = collect[Number(match[1])];
|
|
93
|
+
out.push({
|
|
94
|
+
node,
|
|
95
|
+
children: toJsxChunks(children, collect)
|
|
96
|
+
});
|
|
97
|
+
idx = match.index + match[0].length;
|
|
98
|
+
}
|
|
99
|
+
if (idx < text.length) out.push(text.slice(idx));
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Generate the component export as an ESM node with estree, for the MDX.js compiler.
|
|
104
|
+
*/
|
|
105
|
+
function jsxToEstree(as, chunks) {
|
|
106
|
+
const hasJsx = chunks.some((chunk) => typeof chunk !== "string");
|
|
107
|
+
let value;
|
|
108
|
+
if (chunks.length === 0) value = literal("");
|
|
109
|
+
else if (typeof chunks[0] === "string" && chunks.length === 1) value = literal(chunks[0]);
|
|
110
|
+
else if (chunks.length === 1) value = elementToEstree(chunks[0]);
|
|
111
|
+
else value = {
|
|
112
|
+
type: "JSXFragment",
|
|
113
|
+
openingFragment: { type: "JSXOpeningFragment" },
|
|
114
|
+
closingFragment: { type: "JSXClosingFragment" },
|
|
115
|
+
children: childrenToEstree(chunks)
|
|
116
|
+
};
|
|
117
|
+
const body = [{
|
|
118
|
+
type: "IfStatement",
|
|
119
|
+
test: {
|
|
120
|
+
type: "UnaryExpression",
|
|
121
|
+
operator: "!",
|
|
122
|
+
prefix: true,
|
|
123
|
+
argument: {
|
|
124
|
+
type: "CallExpression",
|
|
125
|
+
callee: {
|
|
126
|
+
type: "Identifier",
|
|
127
|
+
name: "_asMarkdown"
|
|
128
|
+
},
|
|
129
|
+
arguments: [],
|
|
130
|
+
optional: false
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
consequent: {
|
|
134
|
+
type: "ReturnStatement",
|
|
135
|
+
argument: literal(null)
|
|
136
|
+
},
|
|
137
|
+
alternate: null
|
|
138
|
+
}];
|
|
139
|
+
if (hasJsx) body.push({
|
|
140
|
+
type: "VariableDeclaration",
|
|
141
|
+
kind: "const",
|
|
142
|
+
declarations: [{
|
|
143
|
+
type: "VariableDeclarator",
|
|
144
|
+
id: {
|
|
145
|
+
type: "Identifier",
|
|
146
|
+
name: "_c"
|
|
147
|
+
},
|
|
148
|
+
init: {
|
|
149
|
+
type: "CallExpression",
|
|
150
|
+
callee: {
|
|
151
|
+
type: "Identifier",
|
|
152
|
+
name: "_jsxComponents"
|
|
153
|
+
},
|
|
154
|
+
arguments: [{
|
|
155
|
+
type: "MemberExpression",
|
|
156
|
+
object: {
|
|
157
|
+
type: "Identifier",
|
|
158
|
+
name: "props"
|
|
159
|
+
},
|
|
160
|
+
property: {
|
|
161
|
+
type: "Identifier",
|
|
162
|
+
name: "components"
|
|
163
|
+
},
|
|
164
|
+
computed: false,
|
|
165
|
+
optional: false
|
|
166
|
+
}],
|
|
167
|
+
optional: false
|
|
168
|
+
}
|
|
169
|
+
}]
|
|
170
|
+
});
|
|
171
|
+
body.push({
|
|
172
|
+
type: "ReturnStatement",
|
|
173
|
+
argument: value
|
|
174
|
+
});
|
|
175
|
+
return {
|
|
176
|
+
type: "mdxjsEsm",
|
|
177
|
+
value: "",
|
|
178
|
+
data: { estree: {
|
|
179
|
+
type: "Program",
|
|
180
|
+
sourceType: "module",
|
|
181
|
+
body: [{
|
|
182
|
+
type: "ImportDeclaration",
|
|
183
|
+
attributes: [],
|
|
184
|
+
specifiers: [{
|
|
185
|
+
type: "ImportSpecifier",
|
|
186
|
+
imported: {
|
|
187
|
+
type: "Identifier",
|
|
188
|
+
name: "asMarkdown"
|
|
189
|
+
},
|
|
190
|
+
local: {
|
|
191
|
+
type: "Identifier",
|
|
192
|
+
name: "_asMarkdown"
|
|
193
|
+
}
|
|
194
|
+
}, ...hasJsx ? [{
|
|
195
|
+
type: "ImportSpecifier",
|
|
196
|
+
imported: {
|
|
197
|
+
type: "Identifier",
|
|
198
|
+
name: "jsxComponents"
|
|
199
|
+
},
|
|
200
|
+
local: {
|
|
201
|
+
type: "Identifier",
|
|
202
|
+
name: "_jsxComponents"
|
|
203
|
+
}
|
|
204
|
+
}] : []],
|
|
205
|
+
source: literal("@vezham/docs-core/server")
|
|
206
|
+
}, {
|
|
207
|
+
type: "ExportNamedDeclaration",
|
|
208
|
+
attributes: [],
|
|
209
|
+
specifiers: [],
|
|
210
|
+
declaration: {
|
|
211
|
+
type: "FunctionDeclaration",
|
|
212
|
+
id: {
|
|
213
|
+
type: "Identifier",
|
|
214
|
+
name: as
|
|
215
|
+
},
|
|
216
|
+
params: [{
|
|
217
|
+
type: "Identifier",
|
|
218
|
+
name: "props"
|
|
219
|
+
}],
|
|
220
|
+
body: {
|
|
221
|
+
type: "BlockStatement",
|
|
222
|
+
body
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}]
|
|
226
|
+
} }
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
function literal(value) {
|
|
230
|
+
return {
|
|
231
|
+
type: "Literal",
|
|
232
|
+
value
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
function childrenToEstree(chunks) {
|
|
236
|
+
const out = [];
|
|
237
|
+
for (const chunk of chunks) out.push(typeof chunk === "string" ? {
|
|
238
|
+
type: "JSXExpressionContainer",
|
|
239
|
+
expression: literal(chunk)
|
|
240
|
+
} : elementToEstree(chunk));
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
function elementToEstree({ node, children }) {
|
|
244
|
+
const attributes = [];
|
|
245
|
+
for (const attr of node.attributes) {
|
|
246
|
+
if (attr.type === "mdxJsxExpressionAttribute") {
|
|
247
|
+
const expression = programExpression(attr.data?.estree);
|
|
248
|
+
if (expression?.type === "ObjectExpression" && expression.properties.length === 1 && expression.properties[0].type === "SpreadElement") attributes.push({
|
|
249
|
+
type: "JSXSpreadAttribute",
|
|
250
|
+
argument: expression.properties[0].argument
|
|
251
|
+
});
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
let value = null;
|
|
255
|
+
if (typeof attr.value === "string") value = {
|
|
256
|
+
type: "Literal",
|
|
257
|
+
value: attr.value
|
|
258
|
+
};
|
|
259
|
+
else if (attr.value) {
|
|
260
|
+
const expression = programExpression(attr.value.data?.estree);
|
|
261
|
+
if (!expression) continue;
|
|
262
|
+
value = {
|
|
263
|
+
type: "JSXExpressionContainer",
|
|
264
|
+
expression
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
attributes.push({
|
|
268
|
+
type: "JSXAttribute",
|
|
269
|
+
name: attr.name.includes(":") ? {
|
|
270
|
+
type: "JSXNamespacedName",
|
|
271
|
+
namespace: {
|
|
272
|
+
type: "JSXIdentifier",
|
|
273
|
+
name: attr.name.slice(0, attr.name.indexOf(":"))
|
|
274
|
+
},
|
|
275
|
+
name: {
|
|
276
|
+
type: "JSXIdentifier",
|
|
277
|
+
name: attr.name.slice(attr.name.indexOf(":") + 1)
|
|
278
|
+
}
|
|
279
|
+
} : {
|
|
280
|
+
type: "JSXIdentifier",
|
|
281
|
+
name: attr.name
|
|
282
|
+
},
|
|
283
|
+
value
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
const name = {
|
|
287
|
+
type: "JSXMemberExpression",
|
|
288
|
+
object: {
|
|
289
|
+
type: "JSXIdentifier",
|
|
290
|
+
name: "_c"
|
|
291
|
+
},
|
|
292
|
+
property: {
|
|
293
|
+
type: "JSXIdentifier",
|
|
294
|
+
name: node.name
|
|
295
|
+
}
|
|
296
|
+
};
|
|
297
|
+
const element = {
|
|
298
|
+
type: "JSXElement",
|
|
299
|
+
openingElement: {
|
|
300
|
+
type: "JSXOpeningElement",
|
|
301
|
+
name,
|
|
302
|
+
attributes,
|
|
303
|
+
selfClosing: children.length === 0
|
|
304
|
+
},
|
|
305
|
+
closingElement: children.length === 0 ? null : {
|
|
306
|
+
type: "JSXClosingElement",
|
|
307
|
+
name
|
|
308
|
+
},
|
|
309
|
+
children: childrenToEstree(children)
|
|
310
|
+
};
|
|
311
|
+
if (node.type === "mdxJsxFlowElement") return element;
|
|
312
|
+
return {
|
|
313
|
+
type: "JSXElement",
|
|
314
|
+
openingElement: {
|
|
315
|
+
type: "JSXOpeningElement",
|
|
316
|
+
name: {
|
|
317
|
+
type: "JSXIdentifier",
|
|
318
|
+
name: "span"
|
|
319
|
+
},
|
|
320
|
+
attributes: [],
|
|
321
|
+
selfClosing: false
|
|
322
|
+
},
|
|
323
|
+
closingElement: {
|
|
324
|
+
type: "JSXClosingElement",
|
|
325
|
+
name: {
|
|
326
|
+
type: "JSXIdentifier",
|
|
327
|
+
name: "span"
|
|
328
|
+
}
|
|
329
|
+
},
|
|
330
|
+
children: [element]
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
function programExpression(program) {
|
|
334
|
+
const statement = program?.body[0];
|
|
335
|
+
if (statement?.type === "ExpressionStatement") return statement.expression;
|
|
336
|
+
}
|
|
337
|
+
//#endregion
|
|
338
|
+
export { placeholder, remarkLLMs };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { t as Awaitable } from "../types-D89QoQR-.js";
|
|
2
|
+
//#region src/mdx-plugins/remark-llms.runtime.d.ts
|
|
3
|
+
interface PlaceholderData {
|
|
4
|
+
name: string | null;
|
|
5
|
+
attributes: Record<string, unknown>;
|
|
6
|
+
children: string;
|
|
7
|
+
}
|
|
8
|
+
declare function renderPlaceholder(text: string, renderers: Record<string, (data: PlaceholderData) => Awaitable<string>>): Promise<string>;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { PlaceholderData, renderPlaceholder };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/mdx-plugins/remark-llms.runtime.ts
|
|
2
|
+
const regex = /\0(.+?)\0/gs;
|
|
3
|
+
async function renderPlaceholder(text, renderers) {
|
|
4
|
+
let out = "";
|
|
5
|
+
let idx = 0;
|
|
6
|
+
for (const match of text.matchAll(regex)) {
|
|
7
|
+
out += text.slice(idx, match.index);
|
|
8
|
+
const inner = match[1];
|
|
9
|
+
try {
|
|
10
|
+
const data = JSON.parse(inner);
|
|
11
|
+
const renderer = data.name && renderers[data.name];
|
|
12
|
+
if (data.children.trim()) data.children = await renderPlaceholder(data.children, renderers);
|
|
13
|
+
if (renderer) out += await renderer(data);
|
|
14
|
+
else out += data.children;
|
|
15
|
+
} catch {
|
|
16
|
+
out += match[0];
|
|
17
|
+
}
|
|
18
|
+
idx = match.index + match[0].length;
|
|
19
|
+
}
|
|
20
|
+
out += text.slice(idx);
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
//#endregion
|
|
24
|
+
export { renderPlaceholder };
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
//#region src/mdx-plugins/remark-mdx-files.ts
|
|
4
|
+
function parseFileTree(code) {
|
|
5
|
+
const lines = code.split(/\r?\n/);
|
|
6
|
+
const stack = /* @__PURE__ */ new Map();
|
|
7
|
+
for (const line of lines) {
|
|
8
|
+
let depth = 0;
|
|
9
|
+
let name = line;
|
|
10
|
+
let match;
|
|
11
|
+
while (match = /(?:├──|│|└──)\s*/.exec(name)) {
|
|
12
|
+
name = name.slice(match[0].length);
|
|
13
|
+
depth++;
|
|
14
|
+
}
|
|
15
|
+
if (!name) continue;
|
|
16
|
+
const node = name.endsWith("/") ? {
|
|
17
|
+
type: "folder",
|
|
18
|
+
name,
|
|
19
|
+
children: [],
|
|
20
|
+
depth
|
|
21
|
+
} : {
|
|
22
|
+
type: "file",
|
|
23
|
+
name,
|
|
24
|
+
depth
|
|
25
|
+
};
|
|
26
|
+
let parent;
|
|
27
|
+
for (let i = depth - 1; i >= 0 && !parent; i--) parent = stack.get(i);
|
|
28
|
+
stack.set(depth, node);
|
|
29
|
+
if (!parent) continue;
|
|
30
|
+
if (parent.type === "file") Object.assign(parent, {
|
|
31
|
+
type: "folder",
|
|
32
|
+
children: []
|
|
33
|
+
});
|
|
34
|
+
parent.children.push(node);
|
|
35
|
+
}
|
|
36
|
+
return stack.get(0);
|
|
37
|
+
}
|
|
38
|
+
function defaultToMDX(node, options, depth = 0) {
|
|
39
|
+
if (depth === 0) return {
|
|
40
|
+
type: "mdxJsxFlowElement",
|
|
41
|
+
name: "Files",
|
|
42
|
+
attributes: [],
|
|
43
|
+
children: [defaultToMDX(node, options, depth + 1)]
|
|
44
|
+
};
|
|
45
|
+
const attributes = [{
|
|
46
|
+
type: "mdxJsxAttribute",
|
|
47
|
+
name: "name",
|
|
48
|
+
value: node.name
|
|
49
|
+
}];
|
|
50
|
+
if (node.type === "file") return {
|
|
51
|
+
type: "mdxJsxFlowElement",
|
|
52
|
+
attributes,
|
|
53
|
+
children: [],
|
|
54
|
+
name: "File"
|
|
55
|
+
};
|
|
56
|
+
if (options.defaultOpenAll) attributes.push({
|
|
57
|
+
type: "mdxJsxAttribute",
|
|
58
|
+
name: "defaultOpen",
|
|
59
|
+
value: null
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
type: "mdxJsxFlowElement",
|
|
63
|
+
attributes,
|
|
64
|
+
name: "Folder",
|
|
65
|
+
children: node.children.map((item) => defaultToMDX(item, options, depth + 1))
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
*
|
|
70
|
+
* **Files CodeBlock:**
|
|
71
|
+
*
|
|
72
|
+
* Convert codeblocks with `files` as lang, like:
|
|
73
|
+
*
|
|
74
|
+
* ```files
|
|
75
|
+
* project
|
|
76
|
+
* ├── src
|
|
77
|
+
* │ ├── index.js
|
|
78
|
+
* │ └── utils
|
|
79
|
+
* │ └── helper.js
|
|
80
|
+
* ├── package.json
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* into MDX `<Files />` component.
|
|
84
|
+
*
|
|
85
|
+
* **Auto Files:**
|
|
86
|
+
*
|
|
87
|
+
* Generates MDX `<Files />` component from file system.
|
|
88
|
+
*
|
|
89
|
+
* ```mdx
|
|
90
|
+
* <auto-files dir="scripts" pattern="my-dir/*" defaultOpenAll />
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
function remarkMdxFiles(options = {}) {
|
|
94
|
+
const { lang = "files", toMdx = defaultToMDX } = options;
|
|
95
|
+
async function autoFiles(file, node, { patterns, dir, defaultOpenAll = false }) {
|
|
96
|
+
const { glob } = await import("tinyglobby");
|
|
97
|
+
if (!patterns) file.fail("Missing `pattern` prop in <auto-files>", { place: node.position });
|
|
98
|
+
const baseDir = file.dirname ?? file.cwd;
|
|
99
|
+
const cwd = dir ? path.join(baseDir, dir) : baseDir;
|
|
100
|
+
const files = await glob(patterns, { cwd });
|
|
101
|
+
Object.assign(node, toMdx(buildFileTreeFromGlob(cwd, files), { defaultOpenAll }));
|
|
102
|
+
}
|
|
103
|
+
return async (tree, file) => {
|
|
104
|
+
const queue = [];
|
|
105
|
+
visit(tree, ["code", "mdxJsxFlowElement"], (node) => {
|
|
106
|
+
if (node.type === "code") {
|
|
107
|
+
if (node.lang !== lang || !node.value) return;
|
|
108
|
+
const fileTree = parseFileTree(node.value);
|
|
109
|
+
if (!fileTree) return;
|
|
110
|
+
Object.assign(node, toMdx(fileTree, { defaultOpenAll: true }));
|
|
111
|
+
return "skip";
|
|
112
|
+
}
|
|
113
|
+
if (node.type === "mdxJsxFlowElement") {
|
|
114
|
+
if (node.name !== "auto-files") return;
|
|
115
|
+
const parsed = {};
|
|
116
|
+
for (const attr of node.attributes) {
|
|
117
|
+
if (attr.type !== "mdxJsxAttribute") continue;
|
|
118
|
+
const { name, value } = attr;
|
|
119
|
+
switch (name) {
|
|
120
|
+
case "dir":
|
|
121
|
+
if (typeof value === "string") parsed.dir = value;
|
|
122
|
+
break;
|
|
123
|
+
case "pattern":
|
|
124
|
+
if (typeof value === "string") {
|
|
125
|
+
parsed.patterns ??= [];
|
|
126
|
+
parsed.patterns.push(value);
|
|
127
|
+
}
|
|
128
|
+
break;
|
|
129
|
+
case "defaultOpenAll": parsed.defaultOpenAll = true;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
queue.push(autoFiles(file, node, parsed));
|
|
133
|
+
return "skip";
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
await Promise.all(queue);
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function buildFileTreeFromGlob(dir, files) {
|
|
140
|
+
const nodeMap = /* @__PURE__ */ new Map();
|
|
141
|
+
const root = {
|
|
142
|
+
depth: 0,
|
|
143
|
+
type: "folder",
|
|
144
|
+
name: path.basename(dir),
|
|
145
|
+
children: []
|
|
146
|
+
};
|
|
147
|
+
nodeMap.set("", root);
|
|
148
|
+
for (const file of files) {
|
|
149
|
+
const parts = path.normalize(file).split(path.sep).filter((part) => part.length > 0);
|
|
150
|
+
let currentPath = "";
|
|
151
|
+
let current = root;
|
|
152
|
+
for (let i = 0; i < parts.length; i++) {
|
|
153
|
+
const name = parts[i];
|
|
154
|
+
const nextPath = path.join(currentPath, name);
|
|
155
|
+
if (i === parts.length - 1) {
|
|
156
|
+
const fileNode = {
|
|
157
|
+
depth: i + 1,
|
|
158
|
+
type: "file",
|
|
159
|
+
name
|
|
160
|
+
};
|
|
161
|
+
current.children.push(fileNode);
|
|
162
|
+
} else {
|
|
163
|
+
let folder = nodeMap.get(nextPath);
|
|
164
|
+
if (!folder) {
|
|
165
|
+
folder = {
|
|
166
|
+
depth: i + 1,
|
|
167
|
+
type: "folder",
|
|
168
|
+
name,
|
|
169
|
+
children: []
|
|
170
|
+
};
|
|
171
|
+
nodeMap.set(nextPath, folder);
|
|
172
|
+
current.children.push(folder);
|
|
173
|
+
}
|
|
174
|
+
current = folder;
|
|
175
|
+
currentPath = nextPath;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return root;
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
182
|
+
export { remarkMdxFiles };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { visit } from "unist-util-visit";
|
|
2
|
+
//#region src/mdx-plugins/remark-mdx-mermaid.ts
|
|
3
|
+
function toMDX(code) {
|
|
4
|
+
return {
|
|
5
|
+
type: "mdxJsxFlowElement",
|
|
6
|
+
name: "Mermaid",
|
|
7
|
+
attributes: [{
|
|
8
|
+
type: "mdxJsxAttribute",
|
|
9
|
+
name: "chart",
|
|
10
|
+
value: code.trim()
|
|
11
|
+
}],
|
|
12
|
+
children: []
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Convert `mermaid` codeblocks into `<Mermaid />` MDX component
|
|
17
|
+
*/
|
|
18
|
+
function remarkMdxMermaid(options = {}) {
|
|
19
|
+
const { lang = "mermaid" } = options;
|
|
20
|
+
return (tree) => {
|
|
21
|
+
visit(tree, "code", (node, idx, parent) => {
|
|
22
|
+
if (node.lang !== lang || !node.value || typeof idx !== "number" || !parent) return;
|
|
23
|
+
parent.children[idx] = toMDX(node.value);
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { remarkMdxMermaid };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { generateCodeBlockTabs } from "./codeblock-utils.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
import convert from "npm-to-yarn";
|
|
4
|
+
//#region src/mdx-plugins/remark-npm.ts
|
|
5
|
+
function convertLines(cmd, to) {
|
|
6
|
+
return cmd.split("\n").map((l) => convert(l, to)).join("\n");
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* It generates multiple tabs of codeblocks for different package managers from a npm command codeblock.
|
|
10
|
+
*/
|
|
11
|
+
function remarkNpm({ persist = false, packageManagers = [
|
|
12
|
+
{
|
|
13
|
+
command: (cmd) => cmd,
|
|
14
|
+
name: "npm"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
command: (cmd) => convertLines(cmd, "pnpm"),
|
|
18
|
+
name: "pnpm"
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
command: (cmd) => convertLines(cmd, "yarn"),
|
|
22
|
+
name: "yarn"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
command: (cmd) => convertLines(cmd, "bun"),
|
|
26
|
+
name: "bun"
|
|
27
|
+
}
|
|
28
|
+
] } = {}) {
|
|
29
|
+
return (tree) => {
|
|
30
|
+
visit(tree, "code", (node, idx, parent) => {
|
|
31
|
+
if (typeof idx !== "number" || !parent) return;
|
|
32
|
+
let code;
|
|
33
|
+
switch (node.lang) {
|
|
34
|
+
case "package-install":
|
|
35
|
+
code = node.value;
|
|
36
|
+
if (!code.startsWith("npm") && !code.startsWith("npx")) code = `npm install ${code}`;
|
|
37
|
+
break;
|
|
38
|
+
case "npm":
|
|
39
|
+
code = node.value;
|
|
40
|
+
break;
|
|
41
|
+
default: return;
|
|
42
|
+
}
|
|
43
|
+
const options = {
|
|
44
|
+
persist,
|
|
45
|
+
tabs: [],
|
|
46
|
+
triggers: []
|
|
47
|
+
};
|
|
48
|
+
for (const manager of packageManagers) {
|
|
49
|
+
const value = manager.value ?? manager.name;
|
|
50
|
+
const command = manager.command(code);
|
|
51
|
+
if (!command || command.length === 0) continue;
|
|
52
|
+
options.defaultValue ??= value;
|
|
53
|
+
options.triggers.push({
|
|
54
|
+
value,
|
|
55
|
+
children: [{
|
|
56
|
+
type: "text",
|
|
57
|
+
value: manager.name
|
|
58
|
+
}]
|
|
59
|
+
});
|
|
60
|
+
options.tabs.push({
|
|
61
|
+
value,
|
|
62
|
+
children: [{
|
|
63
|
+
type: "code",
|
|
64
|
+
lang: "bash",
|
|
65
|
+
meta: node.meta,
|
|
66
|
+
value: command
|
|
67
|
+
}]
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
parent.children[idx] = generateCodeBlockTabs(options);
|
|
71
|
+
return "skip";
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
//#endregion
|
|
76
|
+
export { remarkNpm };
|