@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,548 @@
|
|
|
1
|
+
import { n as flattenNodeHast } from "./utils-Yx0IL9eW.js";
|
|
2
|
+
import { n as defaultThemes, r as getRequiredThemes } from "./utils-Cgs-6U-z.js";
|
|
3
|
+
import { parseCodeBlockAttributes } from "./mdx-plugins/codeblock-utils.js";
|
|
4
|
+
import { transformerIcon } from "./mdx-plugins/transformer-icon.js";
|
|
5
|
+
import { visit } from "unist-util-visit";
|
|
6
|
+
import { isSpecialLang } from "shiki/core";
|
|
7
|
+
//#region src/mdx-plugins/rehype-code/parsers.ts
|
|
8
|
+
const RE_TAILING_CURLY_COLON = /(.+)\{:([\w-]+)\}$/;
|
|
9
|
+
const InlineCodeParsers = { "tailing-curly-colon": (_tree, node) => {
|
|
10
|
+
const raw = flattenNodeHast(node);
|
|
11
|
+
const match = raw.match(RE_TAILING_CURLY_COLON);
|
|
12
|
+
if (!match) return;
|
|
13
|
+
return {
|
|
14
|
+
structure: "inline",
|
|
15
|
+
code: match[1] ?? raw,
|
|
16
|
+
lang: match.at(2)
|
|
17
|
+
};
|
|
18
|
+
} };
|
|
19
|
+
const languagePrefix = "language-";
|
|
20
|
+
const PreParser = (_tree, node) => {
|
|
21
|
+
const head = node.children[0];
|
|
22
|
+
if (!head || head.type !== "element" || head.tagName !== "code" || !head.properties) return;
|
|
23
|
+
const classes = head.properties.className;
|
|
24
|
+
const languageClass = Array.isArray(classes) ? classes.find((d) => typeof d === "string" && d.startsWith(languagePrefix)) : void 0;
|
|
25
|
+
return {
|
|
26
|
+
structure: "classic",
|
|
27
|
+
lang: typeof languageClass === "string" ? languageClass.slice(9) : void 0,
|
|
28
|
+
code: flattenNodeHast(head),
|
|
29
|
+
meta: head.data?.meta ?? head.properties.metastring?.toString() ?? ""
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/mdx-plugins/rehype-code/shiki.ts
|
|
34
|
+
function rehypeShikiFromHighlighter(highlighter, options) {
|
|
35
|
+
const { addLanguageClass = false, parseMetaString, filterMetaString, cache, defaultLanguage, fallbackLanguage, onError, stripEndNewline = true, inline = false, lazy = true, ...rest } = options;
|
|
36
|
+
function isLanguageLoaded(lang) {
|
|
37
|
+
return isSpecialLang(lang) || highlighter.getLoadedLanguages().includes(lang);
|
|
38
|
+
}
|
|
39
|
+
async function onNode(tree, node, parsed) {
|
|
40
|
+
let { meta: metaString = "", lang = defaultLanguage, code } = parsed;
|
|
41
|
+
if (!lang) return;
|
|
42
|
+
if (!isLanguageLoaded(lang)) {
|
|
43
|
+
if (lazy && lang in highlighter.getBundledLanguages()) await highlighter.loadLanguage(lang);
|
|
44
|
+
else if (fallbackLanguage) {
|
|
45
|
+
lang = fallbackLanguage;
|
|
46
|
+
if (!isLanguageLoaded(fallbackLanguage)) await highlighter.loadLanguage(fallbackLanguage);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (filterMetaString) metaString = filterMetaString(metaString);
|
|
50
|
+
const cacheKey = `${lang}:${metaString}:${code}`;
|
|
51
|
+
const cachedValue = cache?.get(cacheKey);
|
|
52
|
+
if (cachedValue) return cachedValue;
|
|
53
|
+
const transformers = rest.transformers ? [...rest.transformers] : [];
|
|
54
|
+
let _fd_postprocess;
|
|
55
|
+
transformers.push({
|
|
56
|
+
enforce: "post",
|
|
57
|
+
root() {
|
|
58
|
+
_fd_postprocess = this.meta._fd_postprocess;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
if (addLanguageClass) transformers.push(transformerAddLanguage(lang));
|
|
62
|
+
const codeOptions = {
|
|
63
|
+
...rest,
|
|
64
|
+
lang,
|
|
65
|
+
structure: parsed.structure,
|
|
66
|
+
transformers,
|
|
67
|
+
meta: {
|
|
68
|
+
...rest.meta,
|
|
69
|
+
__raw: metaString,
|
|
70
|
+
...parseMetaString?.(metaString, node, tree)
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
if (stripEndNewline && code.endsWith("\n")) code = code.slice(0, -1);
|
|
74
|
+
const fragment = highlighter.codeToHast(code, codeOptions);
|
|
75
|
+
if (_fd_postprocess && _fd_postprocess.length > 0) {
|
|
76
|
+
const ctx = { highlighter };
|
|
77
|
+
await Promise.all(_fd_postprocess.map((v) => v(ctx)));
|
|
78
|
+
}
|
|
79
|
+
cache?.set(cacheKey, fragment);
|
|
80
|
+
if (parsed.structure === "classic") return fragment;
|
|
81
|
+
return {
|
|
82
|
+
type: "element",
|
|
83
|
+
tagName: "code",
|
|
84
|
+
properties: { class: "shiki" },
|
|
85
|
+
children: fragment.children
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
return async (tree) => {
|
|
89
|
+
const queue = [];
|
|
90
|
+
visit(tree, "element", (node, index, parent) => {
|
|
91
|
+
let parsed;
|
|
92
|
+
if (!parent || index == null) return;
|
|
93
|
+
if (node.tagName === "pre") parsed = PreParser(tree, node);
|
|
94
|
+
else if (node.tagName === "code" && inline) parsed = InlineCodeParsers[inline](tree, node);
|
|
95
|
+
else return;
|
|
96
|
+
if (!parsed) return "skip";
|
|
97
|
+
queue.push(onNode(tree, node, parsed).then((fragment) => {
|
|
98
|
+
if (fragment) parent.children[index] = fragment;
|
|
99
|
+
}).catch((error) => {
|
|
100
|
+
if (onError) onError(error);
|
|
101
|
+
else throw error;
|
|
102
|
+
}));
|
|
103
|
+
return "skip";
|
|
104
|
+
});
|
|
105
|
+
if (queue.length > 0) await Promise.all(queue);
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
function transformerAddLanguage(lang) {
|
|
109
|
+
return {
|
|
110
|
+
name: "rehype-shiki:code-language-class",
|
|
111
|
+
code(node) {
|
|
112
|
+
this.addClassToHast(node, `language-${lang}`);
|
|
113
|
+
return node;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region ../../node_modules/.pnpm/@shikijs+transformers@4.4.3/node_modules/@shikijs/transformers/dist/index.mjs
|
|
119
|
+
const RE_SPLIT_COMMENT = /(\s+\/\/)/;
|
|
120
|
+
const RE_V1_END_COMMENT_PREFIX = /(?:\/\/|["'#]|;{1,2}|%{1,2}|--)(\s*)$/;
|
|
121
|
+
const RE_V3_END_COMMENT_PREFIX = /(?:\/\/|#|;{1,2}|%{1,2}|--)(\s*)$/;
|
|
122
|
+
/**
|
|
123
|
+
* some comment formats have to be located at the end of line
|
|
124
|
+
* hence we can skip matching them for other tokens
|
|
125
|
+
*/
|
|
126
|
+
const matchers = [
|
|
127
|
+
[/^(<!--)(.+)(-->)$/, false],
|
|
128
|
+
[/^(\/\*)(.+)(\*\/)$/, false],
|
|
129
|
+
[/^(\/\/|["'#]|;{1,2}|%{1,2}|--)(.*)$/, true],
|
|
130
|
+
[/^(\*)(.+)$/, true]
|
|
131
|
+
];
|
|
132
|
+
/**
|
|
133
|
+
* @param lines line tokens
|
|
134
|
+
* @param jsx enable JSX parsing
|
|
135
|
+
* @param matchAlgorithm matching algorithm
|
|
136
|
+
*/
|
|
137
|
+
function parseComments(lines, jsx, matchAlgorithm) {
|
|
138
|
+
const out = [];
|
|
139
|
+
for (const line of lines) {
|
|
140
|
+
if (matchAlgorithm === "v3") {
|
|
141
|
+
const splittedElements = line.children.flatMap((element, idx) => {
|
|
142
|
+
if (element.type !== "element") return element;
|
|
143
|
+
const token = element.children[0];
|
|
144
|
+
if (token.type !== "text") return element;
|
|
145
|
+
const isLast = idx === line.children.length - 1;
|
|
146
|
+
if (!matchToken(token.value, isLast)) return element;
|
|
147
|
+
const rawSplits = token.value.split(RE_SPLIT_COMMENT);
|
|
148
|
+
if (rawSplits.length <= 1) return element;
|
|
149
|
+
let splits = [rawSplits[0]];
|
|
150
|
+
for (let i = 1; i < rawSplits.length; i += 2) splits.push(rawSplits[i] + (rawSplits[i + 1] || ""));
|
|
151
|
+
splits = splits.filter(Boolean);
|
|
152
|
+
if (splits.length <= 1) return element;
|
|
153
|
+
return splits.map((split) => {
|
|
154
|
+
return {
|
|
155
|
+
...element,
|
|
156
|
+
children: [{
|
|
157
|
+
type: "text",
|
|
158
|
+
value: split
|
|
159
|
+
}]
|
|
160
|
+
};
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
if (splittedElements.length !== line.children.length) line.children = splittedElements;
|
|
164
|
+
}
|
|
165
|
+
const elements = line.children;
|
|
166
|
+
let start = elements.length - 1;
|
|
167
|
+
if (matchAlgorithm === "v1") start = 0;
|
|
168
|
+
else if (jsx) start = elements.length - 2;
|
|
169
|
+
for (let i = Math.max(start, 0); i < elements.length; i++) {
|
|
170
|
+
const token = elements[i];
|
|
171
|
+
if (token.type !== "element") continue;
|
|
172
|
+
const head = token.children.at(0);
|
|
173
|
+
if (head?.type !== "text") continue;
|
|
174
|
+
const isLast = i === elements.length - 1;
|
|
175
|
+
let match = matchToken(head.value, isLast);
|
|
176
|
+
let additionalTokens;
|
|
177
|
+
if (!match && i > 0 && head.value.trim().startsWith("[!code")) {
|
|
178
|
+
const prevToken = elements[i - 1];
|
|
179
|
+
if (prevToken?.type === "element") {
|
|
180
|
+
const prevHead = prevToken.children.at(0);
|
|
181
|
+
if (prevHead?.type === "text" && prevHead.value.includes("//")) {
|
|
182
|
+
const combinedMatch = matchToken(prevHead.value + head.value, isLast);
|
|
183
|
+
if (combinedMatch) {
|
|
184
|
+
match = combinedMatch;
|
|
185
|
+
out.push({
|
|
186
|
+
info: combinedMatch,
|
|
187
|
+
line,
|
|
188
|
+
token: prevToken,
|
|
189
|
+
isLineCommentOnly: elements.length === 2 && prevToken.children.length === 1 && token.children.length === 1,
|
|
190
|
+
isJsxStyle: false,
|
|
191
|
+
additionalTokens: [token]
|
|
192
|
+
});
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (!match) continue;
|
|
199
|
+
if (jsx && !isLast && i !== 0) {
|
|
200
|
+
const isJsxStyle = isValue(elements[i - 1], "{") && isValue(elements[i + 1], "}");
|
|
201
|
+
out.push({
|
|
202
|
+
info: match,
|
|
203
|
+
line,
|
|
204
|
+
token,
|
|
205
|
+
isLineCommentOnly: elements.length === 3 && token.children.length === 1,
|
|
206
|
+
isJsxStyle,
|
|
207
|
+
additionalTokens
|
|
208
|
+
});
|
|
209
|
+
} else out.push({
|
|
210
|
+
info: match,
|
|
211
|
+
line,
|
|
212
|
+
token,
|
|
213
|
+
isLineCommentOnly: elements.length === 1 && token.children.length === 1,
|
|
214
|
+
isJsxStyle: false,
|
|
215
|
+
additionalTokens
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
return out;
|
|
220
|
+
}
|
|
221
|
+
function isValue(element, value) {
|
|
222
|
+
if (element.type !== "element") return false;
|
|
223
|
+
const text = element.children[0];
|
|
224
|
+
if (text.type !== "text") return false;
|
|
225
|
+
return text.value.trim() === value;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* @param text text value of comment node
|
|
229
|
+
* @param isLast whether the token is located at the end of line
|
|
230
|
+
*/
|
|
231
|
+
function matchToken(text, isLast) {
|
|
232
|
+
let trimmed = text.trimStart();
|
|
233
|
+
const spaceFront = text.length - trimmed.length;
|
|
234
|
+
trimmed = trimmed.trimEnd();
|
|
235
|
+
const spaceEnd = text.length - trimmed.length - spaceFront;
|
|
236
|
+
for (const [matcher, endOfLine] of matchers) {
|
|
237
|
+
if (endOfLine && !isLast) continue;
|
|
238
|
+
const result = matcher.exec(trimmed);
|
|
239
|
+
if (!result) continue;
|
|
240
|
+
return [
|
|
241
|
+
" ".repeat(spaceFront) + result[1],
|
|
242
|
+
result[2],
|
|
243
|
+
result[3] ? result[3] + " ".repeat(spaceEnd) : void 0
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Remove empty comment prefixes at line end, e.g. `// `
|
|
249
|
+
*
|
|
250
|
+
* For matchAlgorithm v1
|
|
251
|
+
*/
|
|
252
|
+
function v1ClearEndCommentPrefix(text) {
|
|
253
|
+
const match = text.match(RE_V1_END_COMMENT_PREFIX);
|
|
254
|
+
if (match && match[1].trim().length === 0) return text.slice(0, match.index);
|
|
255
|
+
return text;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Remove empty comment prefixes at line end, e.g. `// `
|
|
259
|
+
*
|
|
260
|
+
* For matchAlgorithm v3
|
|
261
|
+
*/
|
|
262
|
+
function v3ClearEndCommentPrefix(text) {
|
|
263
|
+
const match = text.match(RE_V3_END_COMMENT_PREFIX);
|
|
264
|
+
if (match && match[1].trim().length === 0) return text.slice(0, match.index).trimEnd();
|
|
265
|
+
return text;
|
|
266
|
+
}
|
|
267
|
+
function createCommentNotationTransformer(name, regex, onMatch, matchAlgorithm) {
|
|
268
|
+
matchAlgorithm ??= "v3";
|
|
269
|
+
return {
|
|
270
|
+
name,
|
|
271
|
+
code(code) {
|
|
272
|
+
const lines = code.children.filter((i) => i.type === "element");
|
|
273
|
+
const linesToRemove = [];
|
|
274
|
+
code.data ??= {};
|
|
275
|
+
const data = code.data;
|
|
276
|
+
data._shiki_notation ??= parseComments(lines, ["jsx", "tsx"].includes(this.options.lang), matchAlgorithm);
|
|
277
|
+
const parsed = data._shiki_notation;
|
|
278
|
+
for (const comment of parsed) {
|
|
279
|
+
if (comment.info[1].length === 0) continue;
|
|
280
|
+
let lineIdx = lines.indexOf(comment.line);
|
|
281
|
+
if (comment.isLineCommentOnly && matchAlgorithm !== "v1") lineIdx++;
|
|
282
|
+
let replaced = false;
|
|
283
|
+
comment.info[1] = comment.info[1].replace(regex, (...match) => {
|
|
284
|
+
if (onMatch.call(this, match, comment.line, comment.token, lines, lineIdx)) {
|
|
285
|
+
replaced = true;
|
|
286
|
+
return "";
|
|
287
|
+
}
|
|
288
|
+
return match[0];
|
|
289
|
+
});
|
|
290
|
+
if (!replaced) continue;
|
|
291
|
+
if (matchAlgorithm === "v1") comment.info[1] = v1ClearEndCommentPrefix(comment.info[1]);
|
|
292
|
+
else if (matchAlgorithm === "v3") comment.info[1] = v3ClearEndCommentPrefix(comment.info[1]);
|
|
293
|
+
const isEmpty = comment.info[1].trim().length === 0;
|
|
294
|
+
if (isEmpty) comment.info[1] = "";
|
|
295
|
+
if (isEmpty && comment.isLineCommentOnly) linesToRemove.push(comment.line);
|
|
296
|
+
else if (isEmpty && comment.isJsxStyle) comment.line.children.splice(comment.line.children.indexOf(comment.token) - 1, 3);
|
|
297
|
+
else if (isEmpty) {
|
|
298
|
+
if (comment.additionalTokens) for (let j = comment.additionalTokens.length - 1; j >= 0; j--) {
|
|
299
|
+
const additionalToken = comment.additionalTokens[j];
|
|
300
|
+
const tokenIndex = comment.line.children.indexOf(additionalToken);
|
|
301
|
+
if (tokenIndex !== -1) comment.line.children.splice(tokenIndex, 1);
|
|
302
|
+
}
|
|
303
|
+
comment.line.children.splice(comment.line.children.indexOf(comment.token), 1);
|
|
304
|
+
} else {
|
|
305
|
+
const head = comment.token.children[0];
|
|
306
|
+
if (head.type === "text") {
|
|
307
|
+
head.value = comment.info.join("");
|
|
308
|
+
if (comment.additionalTokens) for (const additionalToken of comment.additionalTokens) {
|
|
309
|
+
const additionalHead = additionalToken.children[0];
|
|
310
|
+
if (additionalHead?.type === "text") additionalHead.value = "";
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
for (const line of linesToRemove) {
|
|
316
|
+
const index = code.children.indexOf(line);
|
|
317
|
+
const nextLine = code.children[index + 1];
|
|
318
|
+
let removeLength = 1;
|
|
319
|
+
if (nextLine?.type === "text" && nextLine?.value === "\n") removeLength = 2;
|
|
320
|
+
code.children.splice(index, removeLength);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const RE_ESCAPE_SPECIAL = /[.*+?^${}()|[\]\\]/g;
|
|
326
|
+
function escapeRegExp(str) {
|
|
327
|
+
return str.replace(RE_ESCAPE_SPECIAL, "\\$&");
|
|
328
|
+
}
|
|
329
|
+
function transformerNotationMap(options = {}, name = "@shikijs/transformers:notation-map") {
|
|
330
|
+
const { classMap = {}, classActivePre = void 0, classActiveCode = void 0 } = options;
|
|
331
|
+
return createCommentNotationTransformer(name, new RegExp(`#?\\s*\\[!code (${Object.keys(classMap).map(escapeRegExp).join("|")})(:\\d+)?\\]`, "gi"), function([_, match, range = ":1"], _line, _comment, lines, index) {
|
|
332
|
+
const lineNum = Number.parseInt(range.slice(1), 10);
|
|
333
|
+
for (let i = index; i < Math.min(index + lineNum, lines.length); i++) this.addClassToHast(lines[i], classMap[match]);
|
|
334
|
+
if (classActivePre) this.addClassToHast(this.pre, classActivePre);
|
|
335
|
+
if (classActiveCode) this.addClassToHast(this.code, classActiveCode);
|
|
336
|
+
return true;
|
|
337
|
+
}, options.matchAlgorithm);
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Use `[!code ++]` and `[!code --]` to mark added and removed lines.
|
|
341
|
+
*/
|
|
342
|
+
function transformerNotationDiff(options = {}) {
|
|
343
|
+
const { classLineAdd = "diff add", classLineRemove = "diff remove", classActivePre = "has-diff", classActiveCode } = options;
|
|
344
|
+
return transformerNotationMap({
|
|
345
|
+
classMap: {
|
|
346
|
+
"++": classLineAdd,
|
|
347
|
+
"--": classLineRemove
|
|
348
|
+
},
|
|
349
|
+
classActivePre,
|
|
350
|
+
classActiveCode,
|
|
351
|
+
matchAlgorithm: options.matchAlgorithm
|
|
352
|
+
}, "@shikijs/transformers:notation-diff");
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* Allow using `[!code focus]` notation in code to mark focused lines.
|
|
356
|
+
*/
|
|
357
|
+
function transformerNotationFocus(options = {}) {
|
|
358
|
+
const { classActiveLine = "focused", classActivePre = "has-focused", classActiveCode } = options;
|
|
359
|
+
return transformerNotationMap({
|
|
360
|
+
classMap: { focus: classActiveLine },
|
|
361
|
+
classActivePre,
|
|
362
|
+
classActiveCode,
|
|
363
|
+
matchAlgorithm: options.matchAlgorithm
|
|
364
|
+
}, "@shikijs/transformers:notation-focus");
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Allow using `[!code highlight]` notation in code to mark highlighted lines.
|
|
368
|
+
*/
|
|
369
|
+
function transformerNotationHighlight(options = {}) {
|
|
370
|
+
const { classActiveLine = "highlighted", classActivePre = "has-highlighted", classActiveCode } = options;
|
|
371
|
+
return transformerNotationMap({
|
|
372
|
+
classMap: {
|
|
373
|
+
highlight: classActiveLine,
|
|
374
|
+
hl: classActiveLine
|
|
375
|
+
},
|
|
376
|
+
classActivePre,
|
|
377
|
+
classActiveCode,
|
|
378
|
+
matchAlgorithm: options.matchAlgorithm
|
|
379
|
+
}, "@shikijs/transformers:notation-highlight");
|
|
380
|
+
}
|
|
381
|
+
function highlightWordInLine(line, ignoredElement, word, className) {
|
|
382
|
+
const content = getTextContent(line);
|
|
383
|
+
let index = content.indexOf(word);
|
|
384
|
+
while (index !== -1) {
|
|
385
|
+
highlightRange.call(this, line.children, ignoredElement, index, word.length, className);
|
|
386
|
+
index = content.indexOf(word, index + 1);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function getTextContent(element) {
|
|
390
|
+
if (element.type === "text") return element.value;
|
|
391
|
+
if (element.type === "element" && element.tagName === "span") return element.children.map(getTextContent).join("");
|
|
392
|
+
return "";
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* @param elements
|
|
396
|
+
* @param ignoredElement
|
|
397
|
+
* @param index highlight beginning index
|
|
398
|
+
* @param len highlight length
|
|
399
|
+
* @param className class name to add to highlighted nodes
|
|
400
|
+
*/
|
|
401
|
+
function highlightRange(elements, ignoredElement, index, len, className) {
|
|
402
|
+
let currentIdx = 0;
|
|
403
|
+
for (let i = 0; i < elements.length; i++) {
|
|
404
|
+
const element = elements[i];
|
|
405
|
+
if (element.type !== "element" || element.tagName !== "span" || element === ignoredElement) continue;
|
|
406
|
+
const textNode = element.children[0];
|
|
407
|
+
if (textNode.type !== "text") continue;
|
|
408
|
+
if (hasOverlap([currentIdx, currentIdx + textNode.value.length - 1], [index, index + len])) {
|
|
409
|
+
const start = Math.max(0, index - currentIdx);
|
|
410
|
+
const length = len - Math.max(0, currentIdx - index);
|
|
411
|
+
if (length === 0) continue;
|
|
412
|
+
const separated = separateToken(element, textNode, start, length);
|
|
413
|
+
this.addClassToHast(separated[1], className);
|
|
414
|
+
const output = separated.filter(Boolean);
|
|
415
|
+
elements.splice(i, 1, ...output);
|
|
416
|
+
i += output.length - 1;
|
|
417
|
+
}
|
|
418
|
+
currentIdx += textNode.value.length;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
function hasOverlap(range1, range2) {
|
|
422
|
+
return range1[0] <= range2[1] && range1[1] >= range2[0];
|
|
423
|
+
}
|
|
424
|
+
function separateToken(span, textNode, index, len) {
|
|
425
|
+
const text = textNode.value;
|
|
426
|
+
const createNode = (value) => inheritElement(span, { children: [{
|
|
427
|
+
type: "text",
|
|
428
|
+
value
|
|
429
|
+
}] });
|
|
430
|
+
return [
|
|
431
|
+
index > 0 ? createNode(text.slice(0, index)) : void 0,
|
|
432
|
+
createNode(text.slice(index, index + len)),
|
|
433
|
+
index + len < text.length ? createNode(text.slice(index + len)) : void 0
|
|
434
|
+
];
|
|
435
|
+
}
|
|
436
|
+
function inheritElement(original, overrides) {
|
|
437
|
+
return {
|
|
438
|
+
...original,
|
|
439
|
+
properties: { ...original.properties },
|
|
440
|
+
...overrides
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
const RE_CODE_WORD = /\s*\[!code word:((?:\\.|[^:\]])+)(:\d+)?\]/;
|
|
444
|
+
const RE_UNESCAPE = /\\(.)/g;
|
|
445
|
+
function transformerNotationWordHighlight(options = {}) {
|
|
446
|
+
const { classActiveWord = "highlighted-word", classActivePre = void 0 } = options;
|
|
447
|
+
return createCommentNotationTransformer("@shikijs/transformers:notation-highlight-word", RE_CODE_WORD, function([_, word, range], _line, comment, lines, index) {
|
|
448
|
+
const lineNum = range ? Number.parseInt(range.slice(1), 10) : lines.length;
|
|
449
|
+
word = word.replace(RE_UNESCAPE, "$1");
|
|
450
|
+
for (let i = index; i < Math.min(index + lineNum, lines.length); i++) highlightWordInLine.call(this, lines[i], comment, word, classActiveWord);
|
|
451
|
+
if (classActivePre) this.addClassToHast(this.pre, classActivePre);
|
|
452
|
+
return true;
|
|
453
|
+
}, options.matchAlgorithm);
|
|
454
|
+
}
|
|
455
|
+
//#endregion
|
|
456
|
+
//#region src/mdx-plugins/rehype-code.core.ts
|
|
457
|
+
function rehypeCodeDefaultOptions() {
|
|
458
|
+
return {
|
|
459
|
+
...defaultThemes,
|
|
460
|
+
defaultLanguage: "plaintext",
|
|
461
|
+
transformers: [
|
|
462
|
+
transformerNotationHighlight({ matchAlgorithm: "v3" }),
|
|
463
|
+
transformerNotationWordHighlight({ matchAlgorithm: "v3" }),
|
|
464
|
+
transformerNotationDiff({ matchAlgorithm: "v3" }),
|
|
465
|
+
transformerNotationFocus({ matchAlgorithm: "v3" })
|
|
466
|
+
],
|
|
467
|
+
parseMetaString(meta) {
|
|
468
|
+
const parsed = parseCodeBlockAttributes(meta, [
|
|
469
|
+
"title",
|
|
470
|
+
"tab",
|
|
471
|
+
"noCopy",
|
|
472
|
+
"lineNumbers"
|
|
473
|
+
]);
|
|
474
|
+
const data = {};
|
|
475
|
+
for (const [k, v] of Object.entries(parsed.attributes)) {
|
|
476
|
+
if (k === "noCopy") {
|
|
477
|
+
data.allowCopy = "false";
|
|
478
|
+
continue;
|
|
479
|
+
}
|
|
480
|
+
if (k === "lineNumbers") {
|
|
481
|
+
data["data-line-numbers"] = true;
|
|
482
|
+
if (typeof v === "number") data["data-line-numbers-start"] = v;
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
data[k] = v;
|
|
486
|
+
}
|
|
487
|
+
data.__raw = parsed.rest;
|
|
488
|
+
return data;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
}
|
|
492
|
+
function createRehypeCode(highlighterFactory) {
|
|
493
|
+
async function initTransformer(_options) {
|
|
494
|
+
let highlighter;
|
|
495
|
+
let options;
|
|
496
|
+
if (typeof highlighterFactory === "function") {
|
|
497
|
+
const out = await highlighterFactory(_options);
|
|
498
|
+
highlighter = out.highlighter;
|
|
499
|
+
options = out.options;
|
|
500
|
+
} else {
|
|
501
|
+
highlighter = _options?.langAlias ? await highlighterFactory.init(_options) : await highlighterFactory.getOrInit();
|
|
502
|
+
options = _options ?? {};
|
|
503
|
+
}
|
|
504
|
+
const transformers = options.transformers ? [...options.transformers] : [];
|
|
505
|
+
if (options.icon !== false) transformers.push(transformerIcon(options.icon));
|
|
506
|
+
if (options.tab !== false) transformers.push(transformerTab());
|
|
507
|
+
const lazy = options.lazy ?? true;
|
|
508
|
+
let preloadLangs = options.langs;
|
|
509
|
+
if (!lazy) preloadLangs ??= Object.keys(highlighter.getBundledLanguages());
|
|
510
|
+
await Promise.all([highlighter.loadTheme(...getRequiredThemes(options)), preloadLangs && highlighter.loadLanguage(...preloadLangs)]);
|
|
511
|
+
return rehypeShikiFromHighlighter(highlighter, {
|
|
512
|
+
...options,
|
|
513
|
+
transformers
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
return function rehypeCode(_options) {
|
|
517
|
+
const transformer = initTransformer(_options);
|
|
518
|
+
return async (tree, file) => {
|
|
519
|
+
await (await transformer)(tree, file, () => void 0);
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
function transformerTab() {
|
|
524
|
+
return {
|
|
525
|
+
name: "rehype-code:tab",
|
|
526
|
+
root(root) {
|
|
527
|
+
const value = this.options.meta?.tab;
|
|
528
|
+
if (typeof value !== "string") return root;
|
|
529
|
+
console.warn("[Fumadocs] For `tab=\"value\" in codeblocks, please use `remarkCodeTab` plugin instead.");
|
|
530
|
+
return {
|
|
531
|
+
type: "root",
|
|
532
|
+
children: [{
|
|
533
|
+
type: "mdxJsxFlowElement",
|
|
534
|
+
name: "Tab",
|
|
535
|
+
data: { _codeblock: true },
|
|
536
|
+
attributes: [{
|
|
537
|
+
type: "mdxJsxAttribute",
|
|
538
|
+
name: "value",
|
|
539
|
+
value
|
|
540
|
+
}],
|
|
541
|
+
children: root.children
|
|
542
|
+
}]
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
//#endregion
|
|
548
|
+
export { rehypeCodeDefaultOptions as n, transformerTab as r, createRehypeCode as t };
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { n as IconOptions } from "./transformer-icon-DlrneIS3.js";
|
|
2
|
+
import { t as Awaitable } from "./types-D89QoQR-.js";
|
|
3
|
+
import { n as ShikiFactory } from "./index-BMEUQz-F.js";
|
|
4
|
+
import { Processor, Transformer } from "unified";
|
|
5
|
+
import { Element, Root } from "hast";
|
|
6
|
+
import { BuiltinLanguage, BuiltinTheme, CodeOptionsMeta, CodeOptionsThemes, CodeToHastOptionsCommon, HighlighterCore, LanguageInput, ShikiTransformer, TransformerOptions } from "shiki";
|
|
7
|
+
//#region src/mdx-plugins/rehype-code/parsers.d.ts
|
|
8
|
+
type InlineCodeParser = 'tailing-curly-colon';
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/mdx-plugins/rehype-code/shiki.d.ts
|
|
11
|
+
interface MapLike<K = unknown, V = unknown> {
|
|
12
|
+
get: (key: K) => V | undefined;
|
|
13
|
+
set: (key: K, value: V) => this;
|
|
14
|
+
}
|
|
15
|
+
interface RehypeShikiExtraOptions {
|
|
16
|
+
/**
|
|
17
|
+
* Add `language-*` class to code element
|
|
18
|
+
*
|
|
19
|
+
* @default false
|
|
20
|
+
*/
|
|
21
|
+
addLanguageClass?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* The default language to use when is not specified
|
|
24
|
+
*/
|
|
25
|
+
defaultLanguage?: string;
|
|
26
|
+
/**
|
|
27
|
+
* The fallback language to use when specified language is not loaded, or not included in the bundle
|
|
28
|
+
*/
|
|
29
|
+
fallbackLanguage?: string;
|
|
30
|
+
/**
|
|
31
|
+
* Load languages and themes on-demand.
|
|
32
|
+
*
|
|
33
|
+
* @default true
|
|
34
|
+
*/
|
|
35
|
+
lazy?: boolean;
|
|
36
|
+
/**
|
|
37
|
+
* `mdast-util-to-hast` adds a newline to the end of code blocks
|
|
38
|
+
*
|
|
39
|
+
* This option strips that newline from the code block
|
|
40
|
+
*
|
|
41
|
+
* @default true
|
|
42
|
+
* @see https://github.com/syntax-tree/mdast-util-to-hast/blob/f511a93817b131fb73419bf7d24d73a5b8b0f0c2/lib/handlers/code.js#L22
|
|
43
|
+
*/
|
|
44
|
+
stripEndNewline?: boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Custom meta string parser
|
|
47
|
+
* Return an object to merge with `meta`
|
|
48
|
+
*/
|
|
49
|
+
parseMetaString?: (metaString: string, node: Element, tree: Root) => Record<string, unknown> | undefined | null;
|
|
50
|
+
/**
|
|
51
|
+
* Filter meta string before processing
|
|
52
|
+
*/
|
|
53
|
+
filterMetaString?: (metaString: string) => string;
|
|
54
|
+
/**
|
|
55
|
+
* Highlight inline code blocks
|
|
56
|
+
*
|
|
57
|
+
* - `false`: disable inline code block highlighting
|
|
58
|
+
* - `tailing-curly-colon`: highlight with `\`code{:lang}\``
|
|
59
|
+
*
|
|
60
|
+
* @see https://shiki.style/packages/rehype#inline-code
|
|
61
|
+
* @default false
|
|
62
|
+
*/
|
|
63
|
+
inline?: InlineCodeParser | false;
|
|
64
|
+
/**
|
|
65
|
+
* Custom map to cache transformed codeToHast result
|
|
66
|
+
*
|
|
67
|
+
* @default undefined
|
|
68
|
+
*/
|
|
69
|
+
cache?: MapLike<string, Root>;
|
|
70
|
+
/**
|
|
71
|
+
* Chance to handle the error
|
|
72
|
+
* If not provided, the error will be thrown
|
|
73
|
+
*/
|
|
74
|
+
onError?: (error: unknown) => void;
|
|
75
|
+
}
|
|
76
|
+
type RehypeShikiCoreOptions = CodeOptionsThemes<BuiltinTheme> & TransformerOptions & CodeOptionsMeta & RehypeShikiExtraOptions & Omit<CodeToHastOptionsCommon, 'lang'>;
|
|
77
|
+
declare module 'shiki' {
|
|
78
|
+
interface ShikiTransformerContextMeta {
|
|
79
|
+
/** [Fumadocs: rehype-code] run async tasks after process */
|
|
80
|
+
_fd_postprocess?: ((ctx: {
|
|
81
|
+
highlighter: HighlighterCore;
|
|
82
|
+
}) => Promise<void>)[];
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
//#endregion
|
|
86
|
+
//#region src/mdx-plugins/rehype-code.core.d.ts
|
|
87
|
+
declare function rehypeCodeDefaultOptions(): RehypeCodeOptionsCommon;
|
|
88
|
+
type RehypeCodeOptionsCommon = RehypeShikiCoreOptions & {
|
|
89
|
+
/**
|
|
90
|
+
* Language names to include & preload.
|
|
91
|
+
*/
|
|
92
|
+
langs?: Array<LanguageInput | BuiltinLanguage>;
|
|
93
|
+
/**
|
|
94
|
+
* Alias of languages
|
|
95
|
+
* @example { 'my-lang': 'javascript' }
|
|
96
|
+
*/
|
|
97
|
+
langAlias?: Record<string, string>;
|
|
98
|
+
/**
|
|
99
|
+
* Add icon to code blocks
|
|
100
|
+
*/
|
|
101
|
+
icon?: IconOptions | false;
|
|
102
|
+
/**
|
|
103
|
+
* Wrap code blocks in `<Tab>` component when "tab" meta string presents
|
|
104
|
+
*
|
|
105
|
+
* @defaultValue true
|
|
106
|
+
*/
|
|
107
|
+
tab?: boolean;
|
|
108
|
+
};
|
|
109
|
+
declare function createRehypeCode<Options extends Partial<RehypeCodeOptionsCommon> = Partial<RehypeCodeOptionsCommon>>(highlighterFactory: ShikiFactory | ((options?: Options) => Awaitable<{
|
|
110
|
+
highlighter: HighlighterCore;
|
|
111
|
+
options: RehypeCodeOptionsCommon;
|
|
112
|
+
}>)): (this: Processor, _options?: Options) => Transformer<Root, Root>;
|
|
113
|
+
declare function transformerTab(): ShikiTransformer;
|
|
114
|
+
//#endregion
|
|
115
|
+
export { transformerTab as i, createRehypeCode as n, rehypeCodeDefaultOptions as r, RehypeCodeOptionsCommon as t };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Processor, Transformer } from "unified";
|
|
2
|
+
import { Element, Root } from "hast";
|
|
3
|
+
//#region src/mdx-plugins/rehype-toc.d.ts
|
|
4
|
+
interface RehypeTocOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Export the generated toc.
|
|
7
|
+
*
|
|
8
|
+
* - `true` (default): as an ESM export named `toc`.
|
|
9
|
+
* - `false`: disable the plugin.
|
|
10
|
+
*/
|
|
11
|
+
exportToc?: boolean | {
|
|
12
|
+
/**
|
|
13
|
+
* generate to `file.data.rehypeToc`.
|
|
14
|
+
*/
|
|
15
|
+
as: 'data';
|
|
16
|
+
} | {
|
|
17
|
+
/**
|
|
18
|
+
* generate as an ESM export.
|
|
19
|
+
*/
|
|
20
|
+
as: 'esm';
|
|
21
|
+
name: string;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
declare module 'vfile' {
|
|
25
|
+
interface DataMap {
|
|
26
|
+
/**
|
|
27
|
+
* [Fumadocs: rehype-toc] output data.
|
|
28
|
+
*/
|
|
29
|
+
rehypeToc?: RehypeTOCItemType[];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
interface RehypeTOCItemType {
|
|
33
|
+
/**
|
|
34
|
+
* the original heading tag
|
|
35
|
+
*/
|
|
36
|
+
title: Element;
|
|
37
|
+
url: string;
|
|
38
|
+
depth: number;
|
|
39
|
+
_step?: number;
|
|
40
|
+
}
|
|
41
|
+
declare function rehypeToc(this: Processor, { exportToc }?: RehypeTocOptions): Transformer<Root, Root>;
|
|
42
|
+
//#endregion
|
|
43
|
+
export { RehypeTocOptions as n, rehypeToc as r, RehypeTOCItemType as t };
|