@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,90 @@
|
|
|
1
|
+
//#region src/i18n/index.d.ts
|
|
2
|
+
interface I18nConfig<Languages extends string = string> {
|
|
3
|
+
/**
|
|
4
|
+
* Supported locale codes.
|
|
5
|
+
*
|
|
6
|
+
* A page tree will be built for each language.
|
|
7
|
+
*/
|
|
8
|
+
languages: Languages[];
|
|
9
|
+
/**
|
|
10
|
+
* Default locale if not specified
|
|
11
|
+
*/
|
|
12
|
+
defaultLanguage: NoInfer<Languages>;
|
|
13
|
+
/**
|
|
14
|
+
* Don't show the locale prefix on URL.
|
|
15
|
+
*
|
|
16
|
+
* - `always`: Always hide the prefix
|
|
17
|
+
* - `default-locale`: Only hide the default locale
|
|
18
|
+
* - `never`: Never hide the prefix
|
|
19
|
+
*
|
|
20
|
+
* This API uses `NextResponse.rewrite`.
|
|
21
|
+
*
|
|
22
|
+
* @defaultValue 'never'
|
|
23
|
+
*/
|
|
24
|
+
hideLocale?: 'always' | 'default-locale' | 'never';
|
|
25
|
+
/**
|
|
26
|
+
* Used by `loader()`, specify the way to parse i18n file structure.
|
|
27
|
+
*
|
|
28
|
+
* @defaultValue 'dot'
|
|
29
|
+
*/
|
|
30
|
+
parser?: 'dot' | 'dir' | 'none';
|
|
31
|
+
/**
|
|
32
|
+
* the fallback language when the page has no translations available for a given locale.
|
|
33
|
+
*
|
|
34
|
+
* Default to `defaultLanguage`, no fallback when set to `null`.
|
|
35
|
+
*/
|
|
36
|
+
fallbackLanguage?: NoInfer<Languages> | null;
|
|
37
|
+
}
|
|
38
|
+
interface TranslationExtension<Keys extends string = string> {
|
|
39
|
+
keys: readonly Keys[];
|
|
40
|
+
}
|
|
41
|
+
interface TranslationPreset<Keys extends string = string> {
|
|
42
|
+
name: string;
|
|
43
|
+
value: Partial<Record<Keys, string>>;
|
|
44
|
+
}
|
|
45
|
+
interface TranslationsAPI<Languages extends string = string, Keys extends string = string> {
|
|
46
|
+
/** for type inference only, always `undefined` in runtime */
|
|
47
|
+
$inferLanguages: Languages;
|
|
48
|
+
/** for type inference only, always `undefined` in runtime */
|
|
49
|
+
$inferKeys: Keys;
|
|
50
|
+
config: I18nConfig<Languages>;
|
|
51
|
+
get: {
|
|
52
|
+
(lang: Languages): Partial<Record<Keys, string>>;
|
|
53
|
+
(lang: string): Partial<Record<Keys, string>> | undefined;
|
|
54
|
+
};
|
|
55
|
+
/** register allowed translation keys */
|
|
56
|
+
extend<const NewKeys extends string>(extension: TranslationExtension<NewKeys>): TranslationsAPI<Languages, Keys | NewKeys>;
|
|
57
|
+
/** add translations */
|
|
58
|
+
add(overrides: { [Lang in Languages]?: Partial<Record<Keys, string>>; }): TranslationsAPI<Languages, Keys>;
|
|
59
|
+
/** @deprecated the namespace parameter is now unnecessary */
|
|
60
|
+
add(unused: string, overrides: { [Lang in Languages]?: Partial<Record<Keys, string>> & {
|
|
61
|
+
/** @deprecated the label is no longer used */
|
|
62
|
+
[key: string]: string;
|
|
63
|
+
}; }): TranslationsAPI<Languages, Keys>;
|
|
64
|
+
/** add language pack */
|
|
65
|
+
preset: (lang: Languages, preset: TranslationPreset<Keys>) => TranslationsAPI<Languages, Keys>;
|
|
66
|
+
}
|
|
67
|
+
interface I18nAPI<Languages extends string = string> extends I18nConfig<Languages> {
|
|
68
|
+
translations: () => TranslationsAPI<Languages, never>;
|
|
69
|
+
}
|
|
70
|
+
interface SingularTranslationsAPI<Keys extends string = string> {
|
|
71
|
+
/** for type inference only, always `undefined` in runtime */
|
|
72
|
+
$inferKeys: Keys;
|
|
73
|
+
get: () => Partial<Record<Keys, string>>;
|
|
74
|
+
/** register allowed translation keys */
|
|
75
|
+
extend<const NewKeys extends string>(extension: TranslationExtension<NewKeys>): SingularTranslationsAPI<Keys | NewKeys>;
|
|
76
|
+
/** add translations */
|
|
77
|
+
add(overrides: Partial<Record<Keys, string>>): SingularTranslationsAPI<Keys>;
|
|
78
|
+
/** @deprecated the namespace parameter is now unnecessary */
|
|
79
|
+
add(unused: string, overrides: Partial<Record<Keys, string>> & {
|
|
80
|
+
/** @deprecated the label is no longer used */
|
|
81
|
+
[key: string]: string;
|
|
82
|
+
}): SingularTranslationsAPI<Keys>;
|
|
83
|
+
/** add language pack */
|
|
84
|
+
preset: (preset: TranslationPreset<Keys>) => SingularTranslationsAPI<Keys>;
|
|
85
|
+
}
|
|
86
|
+
declare function defineI18n<const Languages extends string>(config: I18nConfig<Languages>): I18nAPI<Languages>;
|
|
87
|
+
/** create translations API without i18n */
|
|
88
|
+
declare function defineTranslations(): SingularTranslationsAPI<never>;
|
|
89
|
+
//#endregion
|
|
90
|
+
export { TranslationPreset as a, defineTranslations as c, TranslationExtension as i, I18nConfig as n, TranslationsAPI as o, SingularTranslationsAPI as r, defineI18n as s, I18nAPI as t };
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { i as Root, n as Item, r as Node, t as Folder } from "./definitions-CFOhwE1k.js";
|
|
2
|
+
//#region src/page-tree/utils.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* Flatten tree to an array of page nodes
|
|
5
|
+
*/
|
|
6
|
+
declare function flattenTree(nodes: Node[]): Item[];
|
|
7
|
+
/**
|
|
8
|
+
* Get neighbours of a page, useful for implementing "previous & next" buttons
|
|
9
|
+
*/
|
|
10
|
+
declare function findNeighbour(tree: Root, url: string, options?: {
|
|
11
|
+
separateRoot?: boolean;
|
|
12
|
+
}): {
|
|
13
|
+
previous?: Item;
|
|
14
|
+
next?: Item;
|
|
15
|
+
};
|
|
16
|
+
declare function getPageTreeRoots(pageTree: Root | Folder): (Root | Folder)[];
|
|
17
|
+
/**
|
|
18
|
+
* Get other **page** nodes that lives under the same parent.
|
|
19
|
+
*
|
|
20
|
+
* note: folders & its index nodes are not considered, use `findSiblings()` for more control.
|
|
21
|
+
*/
|
|
22
|
+
declare function getPageTreePeers(treeOrTrees: Root | Record<string, Root>, url: string): Item[];
|
|
23
|
+
/**
|
|
24
|
+
* Get other tree nodes that lives under the same parent.
|
|
25
|
+
*/
|
|
26
|
+
declare function findSiblings(treeOrTrees: Root | Record<string, Root>, url: string): Node[];
|
|
27
|
+
declare function findParent(from: Root | Folder, url: string): Root | Folder | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Search the path of a node in the tree matched by the matcher.
|
|
30
|
+
*
|
|
31
|
+
* @returns The path to the target node (from starting root), or null if the page doesn't exist
|
|
32
|
+
*/
|
|
33
|
+
declare function findPath(nodes: Node[], matcher: (node: Node) => boolean, options?: {
|
|
34
|
+
includeSeparator?: boolean;
|
|
35
|
+
}): Node[] | null;
|
|
36
|
+
/**
|
|
37
|
+
* Find the structural projection of `page` (under the root folder `from`) in `to`:
|
|
38
|
+
* the page at the same file path relative to the root folder.
|
|
39
|
+
*/
|
|
40
|
+
declare function findProjection(from: Folder, to: Folder, page: Item): Item | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* Perform a depth-first search on page tree visiting every node.
|
|
43
|
+
*
|
|
44
|
+
* @param root - the root of page tree to visit.
|
|
45
|
+
* @param visitor - function to receive nodes, return `skip` to skip the children of current node, `break` to stop the search entirely.
|
|
46
|
+
*/
|
|
47
|
+
declare function visit<Root$1 extends Node | Root>(root: Root$1, visitor: <T extends Node | Root>(node: T, parent?: Root | Folder) => 'skip' | 'break' | T | void): Root$1;
|
|
48
|
+
//#endregion
|
|
49
|
+
export { findSiblings as a, getPageTreeRoots as c, findProjection as i, visit as l, findParent as n, flattenTree as o, findPath as r, getPageTreePeers as s, findNeighbour as t };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
//#region src/utils/is-equal.ts
|
|
2
|
+
function isEqualShallow(a, b) {
|
|
3
|
+
if (a === b) return true;
|
|
4
|
+
if (Array.isArray(a) && Array.isArray(b)) return b.length === a.length && a.every((v, i) => isEqualShallow(v, b[i]));
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { isEqualShallow as t };
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentProps } from "react";
|
|
2
|
+
//#region src/link.d.ts
|
|
3
|
+
interface LinkProps extends ComponentProps<'a'> {
|
|
4
|
+
/**
|
|
5
|
+
* If the href is an external URL
|
|
6
|
+
*
|
|
7
|
+
* automatically determined by default
|
|
8
|
+
*/
|
|
9
|
+
external?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Prefetch links
|
|
12
|
+
*/
|
|
13
|
+
prefetch?: boolean;
|
|
14
|
+
}
|
|
15
|
+
declare function Link({ ref, href, external, prefetch, children, ...props }: LinkProps): import("react").JSX.Element;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { Link, Link as default, LinkProps };
|
package/dist/link.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { Link as Link$1 } from "./framework/index.js";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
//#region src/link.tsx
|
|
5
|
+
function Link({ ref, href = "#", external = !!(href.match(/^\w+:/) || href.startsWith("//")), prefetch, children, ...props }) {
|
|
6
|
+
if (external) return /* @__PURE__ */ jsx("a", {
|
|
7
|
+
ref,
|
|
8
|
+
href,
|
|
9
|
+
rel: "noreferrer noopener",
|
|
10
|
+
target: "_blank",
|
|
11
|
+
...props,
|
|
12
|
+
children
|
|
13
|
+
});
|
|
14
|
+
return /* @__PURE__ */ jsx(Link$1, {
|
|
15
|
+
ref,
|
|
16
|
+
href,
|
|
17
|
+
prefetch,
|
|
18
|
+
...props,
|
|
19
|
+
children
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
//#endregion
|
|
23
|
+
export { Link, Link as default };
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//#region src/mdx-plugins/codeblock-utils.ts
|
|
2
|
+
function generateCodeBlockTabs({ persist = false, defaultValue, triggers, tabs, ...options }) {
|
|
3
|
+
const attributes = [];
|
|
4
|
+
if (options.attributes) attributes.push(...options.attributes);
|
|
5
|
+
if (defaultValue) attributes.push({
|
|
6
|
+
type: "mdxJsxAttribute",
|
|
7
|
+
name: "defaultValue",
|
|
8
|
+
value: defaultValue
|
|
9
|
+
});
|
|
10
|
+
if (typeof persist === "object") attributes.push({
|
|
11
|
+
type: "mdxJsxAttribute",
|
|
12
|
+
name: "groupId",
|
|
13
|
+
value: persist.id
|
|
14
|
+
}, {
|
|
15
|
+
type: "mdxJsxAttribute",
|
|
16
|
+
name: "persist",
|
|
17
|
+
value: null
|
|
18
|
+
});
|
|
19
|
+
const children = [{
|
|
20
|
+
type: "mdxJsxFlowElement",
|
|
21
|
+
name: "CodeBlockTabsList",
|
|
22
|
+
attributes: [],
|
|
23
|
+
children: triggers.map((trigger) => ({
|
|
24
|
+
type: "mdxJsxFlowElement",
|
|
25
|
+
attributes: [{
|
|
26
|
+
type: "mdxJsxAttribute",
|
|
27
|
+
name: "value",
|
|
28
|
+
value: trigger.value
|
|
29
|
+
}],
|
|
30
|
+
name: "CodeBlockTabsTrigger",
|
|
31
|
+
children: trigger.children
|
|
32
|
+
}))
|
|
33
|
+
}];
|
|
34
|
+
for (const tab of tabs) children.push({
|
|
35
|
+
type: "mdxJsxFlowElement",
|
|
36
|
+
name: "CodeBlockTab",
|
|
37
|
+
attributes: [{
|
|
38
|
+
type: "mdxJsxAttribute",
|
|
39
|
+
name: "value",
|
|
40
|
+
value: tab.value
|
|
41
|
+
}],
|
|
42
|
+
children: tab.children
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
type: "mdxJsxFlowElement",
|
|
46
|
+
name: "CodeBlockTabs",
|
|
47
|
+
attributes,
|
|
48
|
+
children
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const AttributeRegex = /(?<=^|\s)(?<name>[a-zA-Z0-9_-]+)(?:=(?:"([^"]*)"|'([^']*)'|(\d+)))?/g;
|
|
52
|
+
/**
|
|
53
|
+
* Parse Fumadocs-style code block attributes from meta string, like `title="hello world"`
|
|
54
|
+
*/
|
|
55
|
+
function parseCodeBlockAttributes(meta, allowedNames) {
|
|
56
|
+
const attributes = {};
|
|
57
|
+
return {
|
|
58
|
+
rest: meta.replaceAll(AttributeRegex, (match, name, value_1, value_2, value_3) => {
|
|
59
|
+
if (allowedNames && !allowedNames.includes(name)) return match;
|
|
60
|
+
if (typeof value_3 === "string") attributes[name] = Number(value_3);
|
|
61
|
+
else attributes[name] = value_1 ?? value_2 ?? null;
|
|
62
|
+
return "";
|
|
63
|
+
}),
|
|
64
|
+
attributes
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
export { generateCodeBlockTabs, parseCodeBlockAttributes };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { n as remarkGfm, t as RemarkGfmOptions } from "../remark-gfm-DpVfAX1x.js";
|
|
2
|
+
import { i as transformerTab } from "../rehype-code.core-BjH1uHWj.js";
|
|
3
|
+
import { r as transformerIcon, t as CodeBlockIcon } from "../transformer-icon-DlrneIS3.js";
|
|
4
|
+
import { n as rehypeCode, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-D-RFJb9W.js";
|
|
5
|
+
import { n as remarkImage, t as RemarkImageOptions } from "../remark-image-BI2S9LOb.js";
|
|
6
|
+
import { a as defaultStringifier, c as structure, i as StructuredData, n as StringifyOptions, o as remarkStructure, r as StructureOptions, s as remarkStructureDefaultOptions, t as Stringifier } from "../remark-structure-CnHwvNZr.js";
|
|
7
|
+
import { n as remarkHeading, t as RemarkHeadingOptions } from "../remark-heading-DEIzTkU5.js";
|
|
8
|
+
import { n as remarkAdmonition, t as RemarkAdmonitionOptions } from "../remark-admonition-BwTcmI_S.js";
|
|
9
|
+
import { n as remarkDirectiveAdmonition, t as RemarkDirectiveAdmonitionOptions } from "../remark-directive-admonition-BLiJ5l43.js";
|
|
10
|
+
import { n as RehypeTocOptions, r as rehypeToc, t as RehypeTOCItemType } from "../rehype-toc-K51AGb5U.js";
|
|
11
|
+
import { n as remarkCodeTab, t as RemarkCodeTabOptions } from "../remark-code-tab-DE_4bdnu.js";
|
|
12
|
+
import { n as remarkSteps, t as RemarkStepsOptions } from "../remark-steps-DqVEo0iq.js";
|
|
13
|
+
import { n as remarkNpm, t as RemarkNpmOptions } from "../remark-npm-BbpvkJaT.js";
|
|
14
|
+
import { i as parseCodeBlockAttributes, n as CodeBlockTabsOptions, r as generateCodeBlockTabs, t as CodeBlockAttributes } from "../codeblock-utils-CyP8qsYv.js";
|
|
15
|
+
import { a as remarkMdxFiles, r as RemarkMdxFilesOptions } from "../remark-mdx-files-Buvxc-sa.js";
|
|
16
|
+
import { n as remarkMdxMermaid, t as RemarkMdxMermaidOptions } from "../remark-mdx-mermaid-C1bCHHc6.js";
|
|
17
|
+
import { n as RemarkFeedbackBlockOptions, r as remarkFeedbackBlock, t as FeedbackBlockProps } from "../remark-feedback-block-BxtINXN-.js";
|
|
18
|
+
import { t as LLMsOptions } from "../remark-llms-bD3WvU2V.js";
|
|
19
|
+
import "../index-DAYtLGbx.js";
|
|
20
|
+
export { CodeBlockAttributes, type CodeBlockIcon, CodeBlockTabsOptions, FeedbackBlockProps, type LLMsOptions, RehypeCodeOptions, RehypeTOCItemType, RehypeTocOptions, RemarkAdmonitionOptions, RemarkCodeTabOptions, RemarkDirectiveAdmonitionOptions, RemarkFeedbackBlockOptions, type RemarkGfmOptions, RemarkHeadingOptions, RemarkImageOptions, type RemarkMdxFilesOptions, RemarkMdxMermaidOptions, RemarkNpmOptions, RemarkStepsOptions, Stringifier, StringifyOptions, StructureOptions, StructuredData, defaultStringifier, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkFeedbackBlock, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { remarkHeading } from "./remark-heading.js";
|
|
2
|
+
import { generateCodeBlockTabs, parseCodeBlockAttributes } from "./codeblock-utils.js";
|
|
3
|
+
import { remarkGfm } from "./remark-gfm.js";
|
|
4
|
+
import { r as transformerTab } from "../rehype-code.core-BUwNuchP.js";
|
|
5
|
+
import { transformerIcon } from "./transformer-icon.js";
|
|
6
|
+
import { rehypeCode, rehypeCodeDefaultOptions } from "./rehype-code.js";
|
|
7
|
+
import { remarkImage } from "./remark-image.js";
|
|
8
|
+
import { defaultStringifier, remarkStructure, remarkStructureDefaultOptions, structure } from "./remark-structure.js";
|
|
9
|
+
import { remarkAdmonition } from "./remark-admonition.js";
|
|
10
|
+
import { remarkDirectiveAdmonition } from "./remark-directive-admonition.js";
|
|
11
|
+
import { rehypeToc } from "./rehype-toc.js";
|
|
12
|
+
import { remarkCodeTab } from "./remark-code-tab.js";
|
|
13
|
+
import { remarkSteps } from "./remark-steps.js";
|
|
14
|
+
import { remarkNpm } from "./remark-npm.js";
|
|
15
|
+
import { remarkMdxFiles } from "./remark-mdx-files.js";
|
|
16
|
+
import { remarkMdxMermaid } from "./remark-mdx-mermaid.js";
|
|
17
|
+
import { remarkFeedbackBlock } from "./remark-feedback-block.js";
|
|
18
|
+
export { defaultStringifier, generateCodeBlockTabs, parseCodeBlockAttributes, rehypeCode, rehypeCodeDefaultOptions, rehypeToc, remarkAdmonition, remarkCodeTab, remarkDirectiveAdmonition, remarkFeedbackBlock, remarkGfm, remarkHeading, remarkImage, remarkMdxFiles, remarkMdxMermaid, remarkNpm, remarkSteps, remarkStructure, remarkStructureDefaultOptions, structure, transformerIcon, transformerTab };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { i as transformerTab, n as createRehypeCode, r as rehypeCodeDefaultOptions, t as RehypeCodeOptionsCommon } from "../rehype-code.core-BjH1uHWj.js";
|
|
2
|
+
import { r as transformerIcon, t as CodeBlockIcon } from "../transformer-icon-DlrneIS3.js";
|
|
3
|
+
export { type CodeBlockIcon, RehypeCodeOptionsCommon, createRehypeCode, rehypeCodeDefaultOptions, transformerIcon, transformerTab };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { i as transformerTab } from "../rehype-code.core-BjH1uHWj.js";
|
|
2
|
+
import { r as transformerIcon, t as CodeBlockIcon } from "../transformer-icon-DlrneIS3.js";
|
|
3
|
+
import { n as rehypeCode, r as rehypeCodeDefaultOptions, t as RehypeCodeOptions } from "../rehype-code-D-RFJb9W.js";
|
|
4
|
+
export { type CodeBlockIcon, RehypeCodeOptions, rehypeCode, rehypeCodeDefaultOptions, transformerIcon, transformerTab };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { defaultShikiFactory, wasmShikiFactory } from "../highlight/shiki/full.js";
|
|
2
|
+
import { n as rehypeCodeDefaultOptions$1, r as transformerTab, t as createRehypeCode } from "../rehype-code.core-BUwNuchP.js";
|
|
3
|
+
import { transformerIcon } from "./transformer-icon.js";
|
|
4
|
+
//#region src/mdx-plugins/rehype-code.ts
|
|
5
|
+
const rehypeCodeDefaultOptions = {
|
|
6
|
+
engine: "js",
|
|
7
|
+
...rehypeCodeDefaultOptions$1()
|
|
8
|
+
};
|
|
9
|
+
const rehypeCode = createRehypeCode(async (_options) => {
|
|
10
|
+
const options = {
|
|
11
|
+
...rehypeCodeDefaultOptions,
|
|
12
|
+
..._options
|
|
13
|
+
};
|
|
14
|
+
const factory = options.engine === "oniguruma" ? wasmShikiFactory : defaultShikiFactory;
|
|
15
|
+
let highlighter;
|
|
16
|
+
if (options.langAlias) highlighter = await factory.init({ langAlias: options.langAlias });
|
|
17
|
+
else highlighter = await factory.getOrInit();
|
|
18
|
+
return {
|
|
19
|
+
highlighter,
|
|
20
|
+
options
|
|
21
|
+
};
|
|
22
|
+
});
|
|
23
|
+
//#endregion
|
|
24
|
+
export { rehypeCode, rehypeCodeDefaultOptions, transformerIcon, transformerTab };
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { a as toMdxExportRaw, r as handleTag } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
import { toEstree } from "hast-util-to-estree";
|
|
4
|
+
//#region src/mdx-plugins/rehype-toc.ts
|
|
5
|
+
const TocOnlyTag = "[toc]";
|
|
6
|
+
const NoTocTag = "[!toc]";
|
|
7
|
+
const HeadingTags = /* @__PURE__ */ new Set([
|
|
8
|
+
"h1",
|
|
9
|
+
"h2",
|
|
10
|
+
"h3",
|
|
11
|
+
"h4",
|
|
12
|
+
"h5",
|
|
13
|
+
"h6"
|
|
14
|
+
]);
|
|
15
|
+
function rehypeToc({ exportToc = true } = {}) {
|
|
16
|
+
if (exportToc === true) exportToc = {
|
|
17
|
+
as: "esm",
|
|
18
|
+
name: "toc"
|
|
19
|
+
};
|
|
20
|
+
if (exportToc === false) return () => void 0;
|
|
21
|
+
return (tree, file) => {
|
|
22
|
+
const items = [];
|
|
23
|
+
visit(tree, "element", (element, idx, parent) => {
|
|
24
|
+
if (!HeadingTags.has(element.tagName) || element.children.length === 0) return;
|
|
25
|
+
const id = element.properties.id;
|
|
26
|
+
if (typeof id !== "string") return "skip";
|
|
27
|
+
let isTocOnly = false;
|
|
28
|
+
const last = element.children[element.children.length - 1];
|
|
29
|
+
if (last.type === "text") {
|
|
30
|
+
const noToc = handleTag(last.value, NoTocTag);
|
|
31
|
+
if (noToc !== false) {
|
|
32
|
+
last.value = noToc;
|
|
33
|
+
return "skip";
|
|
34
|
+
}
|
|
35
|
+
const tocOnly = handleTag(last.value, TocOnlyTag);
|
|
36
|
+
if (tocOnly !== false) {
|
|
37
|
+
isTocOnly = true;
|
|
38
|
+
last.value = tocOnly;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
items.push({
|
|
42
|
+
title: element,
|
|
43
|
+
depth: Number(element.tagName[1]),
|
|
44
|
+
url: `#${id}`,
|
|
45
|
+
_step: typeof element.properties["data-fd-step"] === "number" ? element.properties["data-fd-step"] : void 0
|
|
46
|
+
});
|
|
47
|
+
if (isTocOnly && parent && typeof idx === "number") parent.children.splice(idx, 1);
|
|
48
|
+
return "skip";
|
|
49
|
+
});
|
|
50
|
+
if (exportToc.as === "esm") {
|
|
51
|
+
const esmItems = [];
|
|
52
|
+
for (const item of items) {
|
|
53
|
+
const root = toEstree(item.title, {
|
|
54
|
+
elementAttributeNameCase: "react",
|
|
55
|
+
stylePropertyNameCase: "dom"
|
|
56
|
+
}).body[0];
|
|
57
|
+
if (root.type === "ExpressionStatement" && root.expression.type === "JSXElement") esmItems.push({
|
|
58
|
+
...item,
|
|
59
|
+
title: root.expression
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
tree.children.push(toMdxExportRaw(exportToc.name, {
|
|
63
|
+
type: "ArrayExpression",
|
|
64
|
+
elements: esmItems.map((item) => {
|
|
65
|
+
const obj = {
|
|
66
|
+
type: "ObjectExpression",
|
|
67
|
+
properties: [
|
|
68
|
+
{
|
|
69
|
+
type: "Property",
|
|
70
|
+
method: false,
|
|
71
|
+
shorthand: false,
|
|
72
|
+
computed: false,
|
|
73
|
+
key: {
|
|
74
|
+
type: "Identifier",
|
|
75
|
+
name: "depth"
|
|
76
|
+
},
|
|
77
|
+
value: {
|
|
78
|
+
type: "Literal",
|
|
79
|
+
value: item.depth
|
|
80
|
+
},
|
|
81
|
+
kind: "init"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
type: "Property",
|
|
85
|
+
method: false,
|
|
86
|
+
shorthand: false,
|
|
87
|
+
computed: false,
|
|
88
|
+
key: {
|
|
89
|
+
type: "Identifier",
|
|
90
|
+
name: "url"
|
|
91
|
+
},
|
|
92
|
+
value: {
|
|
93
|
+
type: "Literal",
|
|
94
|
+
value: item.url
|
|
95
|
+
},
|
|
96
|
+
kind: "init"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
type: "Property",
|
|
100
|
+
method: false,
|
|
101
|
+
shorthand: false,
|
|
102
|
+
computed: false,
|
|
103
|
+
key: {
|
|
104
|
+
type: "Identifier",
|
|
105
|
+
name: "title"
|
|
106
|
+
},
|
|
107
|
+
value: {
|
|
108
|
+
type: "JSXFragment",
|
|
109
|
+
openingFragment: { type: "JSXOpeningFragment" },
|
|
110
|
+
closingFragment: { type: "JSXClosingFragment" },
|
|
111
|
+
children: item.title.children
|
|
112
|
+
},
|
|
113
|
+
kind: "init"
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
};
|
|
117
|
+
if (typeof item._step === "number") obj.properties.push({
|
|
118
|
+
type: "Property",
|
|
119
|
+
method: false,
|
|
120
|
+
shorthand: false,
|
|
121
|
+
computed: false,
|
|
122
|
+
key: {
|
|
123
|
+
type: "Identifier",
|
|
124
|
+
name: "_step"
|
|
125
|
+
},
|
|
126
|
+
value: {
|
|
127
|
+
type: "Literal",
|
|
128
|
+
value: item._step
|
|
129
|
+
},
|
|
130
|
+
kind: "init"
|
|
131
|
+
});
|
|
132
|
+
return obj;
|
|
133
|
+
})
|
|
134
|
+
}));
|
|
135
|
+
} else file.data.rehypeToc = items;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
//#endregion
|
|
139
|
+
export { rehypeToc };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { t as flattenNode } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import { visit } from "unist-util-visit";
|
|
3
|
+
//#region src/mdx-plugins/remark-admonition.ts
|
|
4
|
+
/**
|
|
5
|
+
* Remark Plugin to support Admonition syntax
|
|
6
|
+
*
|
|
7
|
+
* Useful when Migrating from Docusaurus
|
|
8
|
+
*
|
|
9
|
+
* @deprecated Use `remarkDirectiveAdmonition` with `remark-directive` configured instead.
|
|
10
|
+
*/
|
|
11
|
+
function remarkAdmonition(options = {}) {
|
|
12
|
+
const tag = options.tag ?? ":::";
|
|
13
|
+
const typeMap = options.typeMap ?? {
|
|
14
|
+
info: "info",
|
|
15
|
+
warn: "warn",
|
|
16
|
+
note: "info",
|
|
17
|
+
tip: "info",
|
|
18
|
+
warning: "warn",
|
|
19
|
+
danger: "error"
|
|
20
|
+
};
|
|
21
|
+
function replaceNodes(nodes) {
|
|
22
|
+
if (nodes.length === 0) return;
|
|
23
|
+
let open = -1;
|
|
24
|
+
let attributes = [];
|
|
25
|
+
let hasIntercept = false;
|
|
26
|
+
for (let i = 0; i < nodes.length; i++) {
|
|
27
|
+
if (nodes[i].type !== "paragraph") continue;
|
|
28
|
+
const text = flattenNode(nodes[i]);
|
|
29
|
+
const typeName = Object.keys(typeMap).find((type) => text.startsWith(`${tag}${type}`));
|
|
30
|
+
if (typeName) {
|
|
31
|
+
if (open !== -1) {
|
|
32
|
+
hasIntercept = true;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
open = i;
|
|
36
|
+
attributes.push({
|
|
37
|
+
type: "mdxJsxAttribute",
|
|
38
|
+
name: "type",
|
|
39
|
+
value: typeMap[typeName]
|
|
40
|
+
});
|
|
41
|
+
const meta = text.slice(`${tag}${typeName}`.length);
|
|
42
|
+
if (meta.startsWith("[") && meta.endsWith("]")) attributes.push({
|
|
43
|
+
type: "mdxJsxAttribute",
|
|
44
|
+
name: "title",
|
|
45
|
+
value: meta.slice(1, -1)
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
if (open !== -1 && text === tag) {
|
|
49
|
+
const children = nodes.slice(open + 1, i);
|
|
50
|
+
nodes.splice(open, i - open + 1, {
|
|
51
|
+
type: "mdxJsxFlowElement",
|
|
52
|
+
name: "Callout",
|
|
53
|
+
attributes,
|
|
54
|
+
children: hasIntercept ? replaceNodes(children) : children
|
|
55
|
+
});
|
|
56
|
+
open = -1;
|
|
57
|
+
hasIntercept = false;
|
|
58
|
+
attributes = [];
|
|
59
|
+
i = open;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return (tree) => {
|
|
64
|
+
visit(tree, (node) => {
|
|
65
|
+
if (!("children" in node)) return;
|
|
66
|
+
replaceNodes(node.children);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { remarkAdmonition };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Transformer } from "unified";
|
|
2
|
+
import { Root, RootContent } from "mdast";
|
|
3
|
+
//#region src/mdx-plugins/remark-block-id.d.ts
|
|
4
|
+
interface RemarkBlockIdOptions {
|
|
5
|
+
/**
|
|
6
|
+
* generate block ID.
|
|
7
|
+
*/
|
|
8
|
+
generateId?: (ctx: {
|
|
9
|
+
node: RootContent;
|
|
10
|
+
text: string;
|
|
11
|
+
}) => string;
|
|
12
|
+
/**
|
|
13
|
+
* determine whether an ID should be generated for a given node.
|
|
14
|
+
*
|
|
15
|
+
* default: `true` for block nodes, otherwise `false`.
|
|
16
|
+
*
|
|
17
|
+
* @returns
|
|
18
|
+
* - `true`: generate an ID for the node.
|
|
19
|
+
* - `false`: skip the current node and look into its children.
|
|
20
|
+
* - `skip`: skip the current node and its children.
|
|
21
|
+
*/
|
|
22
|
+
shouldGenerate?: (node: RootContent) => boolean | 'skip';
|
|
23
|
+
/**
|
|
24
|
+
* Add `data-block="<value>"` to updated nodes, pass `null` to disable.
|
|
25
|
+
*
|
|
26
|
+
* @default "default"
|
|
27
|
+
*/
|
|
28
|
+
addDataAttribute?: string | null;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Generate ID for each block node in Markdown/MDX.
|
|
32
|
+
*
|
|
33
|
+
* Note: the uniqueness is only guaranteed per file.
|
|
34
|
+
*/
|
|
35
|
+
declare function remarkBlockId({ generateId, addDataAttribute, shouldGenerate }?: RemarkBlockIdOptions): Transformer<Root, Root>;
|
|
36
|
+
//#endregion
|
|
37
|
+
export { RemarkBlockIdOptions, remarkBlockId };
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { t as flattenNode } from "../utils-Yx0IL9eW.js";
|
|
2
|
+
import Slugger from "github-slugger";
|
|
3
|
+
import { visit } from "unist-util-visit";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
//#region src/mdx-plugins/remark-block-id.ts
|
|
6
|
+
/**
|
|
7
|
+
* Generate ID for each block node in Markdown/MDX.
|
|
8
|
+
*
|
|
9
|
+
* Note: the uniqueness is only guaranteed per file.
|
|
10
|
+
*/
|
|
11
|
+
function remarkBlockId({ generateId, addDataAttribute = "default", shouldGenerate = (node) => {
|
|
12
|
+
switch (node.type) {
|
|
13
|
+
case "mdxJsxFlowElement": return "skip";
|
|
14
|
+
case "paragraph":
|
|
15
|
+
case "image":
|
|
16
|
+
case "listItem": return true;
|
|
17
|
+
default: return false;
|
|
18
|
+
}
|
|
19
|
+
} } = {}) {
|
|
20
|
+
return (tree) => {
|
|
21
|
+
const slugger = new Slugger();
|
|
22
|
+
visit(tree, (node) => {
|
|
23
|
+
if (node.type === "root" || node.data?.hProperties?.id) return;
|
|
24
|
+
const resolved = shouldGenerate(node);
|
|
25
|
+
if (resolved === false) return;
|
|
26
|
+
if (resolved === "skip") return "skip";
|
|
27
|
+
const text = flattenNode(node).trim();
|
|
28
|
+
if (text.length === 0) return;
|
|
29
|
+
const id = generateId ? slugger.slug(generateId({
|
|
30
|
+
node,
|
|
31
|
+
text
|
|
32
|
+
})) : slugger.slug(createHash("sha256").update(text).digest("base64url"));
|
|
33
|
+
node.data ??= {};
|
|
34
|
+
node.data.hProperties ??= {};
|
|
35
|
+
node.data.hProperties.id = id;
|
|
36
|
+
if (addDataAttribute) node.data.hProperties["data-block"] = addDataAttribute;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export { remarkBlockId };
|