@mintlify/msft-sdk 0.1.0
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/README.md +23 -0
- package/dist/components/content-components/all-components.js +27 -0
- package/dist/components/content-components/all-components.js.map +1 -0
- package/dist/components/content-components/callouts.js +50 -0
- package/dist/components/content-components/callouts.js.map +1 -0
- package/dist/components/content-components/callouts.module.css.js +26 -0
- package/dist/components/content-components/callouts.module.css.js.map +1 -0
- package/dist/components/content-components/code-block.js +86 -0
- package/dist/components/content-components/code-block.js.map +1 -0
- package/dist/components/content-components/code-block.module.css.js +28 -0
- package/dist/components/content-components/code-block.module.css.js.map +1 -0
- package/dist/components/content-components/default-components.js +36 -0
- package/dist/components/content-components/default-components.js.map +1 -0
- package/dist/components/content-components/default-components.module.css.js +12 -0
- package/dist/components/content-components/default-components.module.css.js.map +1 -0
- package/dist/components/content-components/details/details.js +42 -0
- package/dist/components/content-components/details/details.js.map +1 -0
- package/dist/components/content-components/details/details.module.css.js +20 -0
- package/dist/components/content-components/details/details.module.css.js.map +1 -0
- package/dist/components/content-components/heading.js +9 -0
- package/dist/components/content-components/heading.js.map +1 -0
- package/dist/components/content-components/link.js +23 -0
- package/dist/components/content-components/link.js.map +1 -0
- package/dist/components/content-components/link.module.css.js +10 -0
- package/dist/components/content-components/link.module.css.js.map +1 -0
- package/dist/components/content-components/param-name.js +9 -0
- package/dist/components/content-components/param-name.js.map +1 -0
- package/dist/components/content-components/param-name.module.css.js +8 -0
- package/dist/components/content-components/param-name.module.css.js.map +1 -0
- package/dist/components/content-components/table/index.js +122 -0
- package/dist/components/content-components/table/index.js.map +1 -0
- package/dist/components/content-components/table/table-modal.js +64 -0
- package/dist/components/content-components/table/table-modal.js.map +1 -0
- package/dist/components/content-components/table/table-modal.module.css.js +18 -0
- package/dist/components/content-components/table/table-modal.module.css.js.map +1 -0
- package/dist/components/content-components/table/table.module.css.js +30 -0
- package/dist/components/content-components/table/table.module.css.js.map +1 -0
- package/dist/components/content-components/tabs/tab.js +8 -0
- package/dist/components/content-components/tabs/tab.js.map +1 -0
- package/dist/components/content-components/tabs/tabs.js +87 -0
- package/dist/components/content-components/tabs/tabs.js.map +1 -0
- package/dist/components/content-components/tabs/tabs.module.css.js +24 -0
- package/dist/components/content-components/tabs/tabs.module.css.js.map +1 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-context.js +52 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-context.js.map +1 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-selector.js +74 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-selector.js.map +1 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-selector.module.css.js +14 -0
- package/dist/components/content-components/zone-pivots/zone-pivot-selector.module.css.js.map +1 -0
- package/dist/components/content-components/zone-pivots/zone-pivot.js +25 -0
- package/dist/components/content-components/zone-pivots/zone-pivot.js.map +1 -0
- package/dist/components/content-components/zone-pivots/zone-target.js +8 -0
- package/dist/components/content-components/zone-pivots/zone-target.js.map +1 -0
- package/dist/components/mdx-renderer.js +13 -0
- package/dist/components/mdx-renderer.js.map +1 -0
- package/dist/components/mdx-renderer.module.css.js +8 -0
- package/dist/components/mdx-renderer.module.css.js.map +1 -0
- package/dist/components/nav-tree/dropdown-menu.js +68 -0
- package/dist/components/nav-tree/dropdown-menu.js.map +1 -0
- package/dist/components/nav-tree/dropdown-menu.module.css.js +52 -0
- package/dist/components/nav-tree/dropdown-menu.module.css.js.map +1 -0
- package/dist/components/nav-tree/index.js +126 -0
- package/dist/components/nav-tree/index.js.map +1 -0
- package/dist/components/nav-tree/mobile-nav.js +60 -0
- package/dist/components/nav-tree/mobile-nav.js.map +1 -0
- package/dist/components/nav-tree/mobile-nav.module.css.js +22 -0
- package/dist/components/nav-tree/mobile-nav.module.css.js.map +1 -0
- package/dist/components/nav-tree/nav-tree.module.css.js +34 -0
- package/dist/components/nav-tree/nav-tree.module.css.js.map +1 -0
- package/dist/components/page-context-menu.js +123 -0
- package/dist/components/page-context-menu.js.map +1 -0
- package/dist/components/page-context-menu.module.css.js +42 -0
- package/dist/components/page-context-menu.module.css.js.map +1 -0
- package/dist/components/page.js +85 -0
- package/dist/components/page.js.map +1 -0
- package/dist/components/page.module.css.js +48 -0
- package/dist/components/page.module.css.js.map +1 -0
- package/dist/components/prose.module.css.js +8 -0
- package/dist/components/prose.module.css.js.map +1 -0
- package/dist/components/toc/index.js +65 -0
- package/dist/components/toc/index.js.map +1 -0
- package/dist/components/toc/pivot-aware-toc.js +23 -0
- package/dist/components/toc/pivot-aware-toc.js.map +1 -0
- package/dist/components/toc/toc.module.css.js +18 -0
- package/dist/components/toc/toc.module.css.js.map +1 -0
- package/dist/hooks/useMarkdownCopy.js +50 -0
- package/dist/hooks/useMarkdownCopy.js.map +1 -0
- package/dist/index.d.ts +313 -0
- package/dist/index.js +45 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/convert-html-to-mdx.js +28 -0
- package/dist/parser/convert-html-to-mdx.js.map +1 -0
- package/dist/parser/serialize-mdx.js +36 -0
- package/dist/parser/serialize-mdx.js.map +1 -0
- package/dist/plugins/rehype/rehype-code-blocks.js +44 -0
- package/dist/plugins/rehype/rehype-code-blocks.js.map +1 -0
- package/dist/plugins/remark/remark-heading-ids.js +23 -0
- package/dist/plugins/remark/remark-heading-ids.js.map +1 -0
- package/dist/plugins/sanitize/rehype-callouts.js +32 -0
- package/dist/plugins/sanitize/rehype-callouts.js.map +1 -0
- package/dist/plugins/sanitize/rehype-details.js +18 -0
- package/dist/plugins/sanitize/rehype-details.js.map +1 -0
- package/dist/plugins/sanitize/rehype-heading-ids.js +22 -0
- package/dist/plugins/sanitize/rehype-heading-ids.js.map +1 -0
- package/dist/plugins/sanitize/rehype-param-name.js +11 -0
- package/dist/plugins/sanitize/rehype-param-name.js.map +1 -0
- package/dist/plugins/sanitize/rehype-pre-to-mdx-fence.js +29 -0
- package/dist/plugins/sanitize/rehype-pre-to-mdx-fence.js.map +1 -0
- package/dist/plugins/sanitize/rehype-remark.js +50 -0
- package/dist/plugins/sanitize/rehype-remark.js.map +1 -0
- package/dist/plugins/sanitize/rehype-table-align.js +52 -0
- package/dist/plugins/sanitize/rehype-table-align.js.map +1 -0
- package/dist/plugins/sanitize/rehype-tabs.js +51 -0
- package/dist/plugins/sanitize/rehype-tabs.js.map +1 -0
- package/dist/plugins/sanitize/rehype-zone-pivots.js +106 -0
- package/dist/plugins/sanitize/rehype-zone-pivots.js.map +1 -0
- package/dist/plugins/sanitize/remove-html-comments.js +17 -0
- package/dist/plugins/sanitize/remove-html-comments.js.map +1 -0
- package/dist/styles.css +1 -0
- package/dist/utils/get-node-text.js +5 -0
- package/dist/utils/get-node-text.js.map +1 -0
- package/dist/utils/rehype.js +17 -0
- package/dist/utils/rehype.js.map +1 -0
- package/dist/utils/string.js +5 -0
- package/dist/utils/string.js.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as i from "react/jsx-runtime";
|
|
2
|
+
import { jsx as n } from "react/jsx-runtime";
|
|
3
|
+
import { compile as a, run as p } from "@mdx-js/mdx";
|
|
4
|
+
import s from "remark-gfm";
|
|
5
|
+
import { rehypeCodeblocks as c } from "../plugins/rehype/rehype-code-blocks.js";
|
|
6
|
+
import { remarkHeadingIds as f } from "../plugins/remark/remark-heading-ids.js";
|
|
7
|
+
import { defaultComponents as l } from "../components/content-components/default-components.js";
|
|
8
|
+
async function x(r) {
|
|
9
|
+
try {
|
|
10
|
+
const o = await a(r, {
|
|
11
|
+
outputFormat: "function-body",
|
|
12
|
+
remarkPlugins: [s, f],
|
|
13
|
+
rehypePlugins: [c]
|
|
14
|
+
}), t = String(o), { default: e } = await p(t, {
|
|
15
|
+
...i
|
|
16
|
+
});
|
|
17
|
+
return (m) => /* @__PURE__ */ n(
|
|
18
|
+
e,
|
|
19
|
+
{
|
|
20
|
+
...m,
|
|
21
|
+
components: {
|
|
22
|
+
...l
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
} catch (o) {
|
|
27
|
+
throw console.error(
|
|
28
|
+
"MDX compilation failed:",
|
|
29
|
+
o instanceof Error ? o.message : String(o)
|
|
30
|
+
), o;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
export {
|
|
34
|
+
x as serializeMdx
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=serialize-mdx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize-mdx.js","sources":["../../src/parser/serialize-mdx.tsx"],"sourcesContent":["import { compile } from \"@mdx-js/mdx\";\nimport { run } from \"@mdx-js/mdx\";\nimport * as runtime from \"react/jsx-runtime\";\nimport React from \"react\";\nimport remarkGfm from \"remark-gfm\";\nimport { rehypeCodeblocks, remarkHeadingIds } from \"../plugins\";\nimport { defaultComponents } from \"../components\";\n\nexport async function serializeMdx(\n mdxString: string\n): Promise<React.ComponentType> {\n try {\n const compiled = await compile(mdxString, {\n outputFormat: \"function-body\",\n remarkPlugins: [remarkGfm, remarkHeadingIds],\n rehypePlugins: [rehypeCodeblocks],\n });\n\n const compiledMdx = String(compiled);\n\n const { default: Content } = await run(compiledMdx, {\n ...runtime,\n });\n\n return (props) => (\n <Content\n {...props}\n components={{\n ...defaultComponents,\n }}\n />\n );\n } catch (error) {\n console.error(\n \"MDX compilation failed:\",\n error instanceof Error ? error.message : String(error)\n );\n throw error;\n }\n}\n"],"names":["serializeMdx","mdxString","compiled","compile","remarkGfm","remarkHeadingIds","rehypeCodeblocks","compiledMdx","Content","run","runtime","props","jsx","defaultComponents","error"],"mappings":";;;;;;;AAQA,eAAsBA,EACpBC,GAC8B;AAC9B,MAAI;AACF,UAAMC,IAAW,MAAMC,EAAQF,GAAW;AAAA,MACxC,cAAc;AAAA,MACd,eAAe,CAACG,GAAWC,CAAgB;AAAA,MAC3C,eAAe,CAACC,CAAgB;AAAA,IAAA,CACjC,GAEKC,IAAc,OAAOL,CAAQ,GAE7B,EAAE,SAASM,EAAA,IAAY,MAAMC,EAAIF,GAAa;AAAA,MAClD,GAAGG;AAAA,IAAA,CACJ;AAED,WAAO,CAACC,MACN,gBAAAC;AAAA,MAACJ;AAAA,MAAA;AAAA,QACE,GAAGG;AAAA,QACJ,YAAY;AAAA,UACV,GAAGE;AAAA,QAAA;AAAA,MACL;AAAA,IAAA;AAAA,EAGN,SAASC,GAAO;AACd,kBAAQ;AAAA,MACN;AAAA,MACAA,aAAiB,QAAQA,EAAM,UAAU,OAAOA,CAAK;AAAA,IAAA,GAEjDA;AAAA,EACR;AACF;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { visit as y } from "unist-util-visit";
|
|
2
|
+
import { isElement as i } from "../../utils/rehype.js";
|
|
3
|
+
import { refractor as N } from "refractor";
|
|
4
|
+
import { toString as d } from "hast-util-to-string";
|
|
5
|
+
const C = () => (f) => {
|
|
6
|
+
y(f, (r, s, a) => {
|
|
7
|
+
var m, n;
|
|
8
|
+
if (a == null || s == null || !i(r) || !i(r, "tagName", "pre"))
|
|
9
|
+
return;
|
|
10
|
+
const e = r.children[0];
|
|
11
|
+
if (!i(e, "tagName", "code")) return;
|
|
12
|
+
const l = (Array.isArray((m = e.properties) == null ? void 0 : m.className) ? e.properties.className.join(" ") : ((n = e.properties) == null ? void 0 : n.className) || "").match(/(?:language|lang)-(\w+)/), t = l ? l[1] : void 0;
|
|
13
|
+
if (t)
|
|
14
|
+
try {
|
|
15
|
+
const o = d(e), h = N.highlight(o, t);
|
|
16
|
+
r.properties || (r.properties = {});
|
|
17
|
+
const p = r.properties.className || [], u = Array.isArray(p) ? p.filter(
|
|
18
|
+
(g) => typeof g == "string" || typeof g == "number"
|
|
19
|
+
) : [];
|
|
20
|
+
r.properties.className = [...u, `language-${t}`], e.children = h.children;
|
|
21
|
+
} catch (o) {
|
|
22
|
+
console.warn(`Failed to highlight code for language "${t}":`, o);
|
|
23
|
+
}
|
|
24
|
+
const c = {
|
|
25
|
+
type: "mdxJsxFlowElement",
|
|
26
|
+
name: "CodeBlock",
|
|
27
|
+
attributes: [
|
|
28
|
+
...t ? [
|
|
29
|
+
{
|
|
30
|
+
type: "mdxJsxAttribute",
|
|
31
|
+
name: "language",
|
|
32
|
+
value: t
|
|
33
|
+
}
|
|
34
|
+
] : []
|
|
35
|
+
],
|
|
36
|
+
children: []
|
|
37
|
+
};
|
|
38
|
+
c.children = [r], a && typeof s == "number" && (a.children[s] = c);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
export {
|
|
42
|
+
C as rehypeCodeblocks
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=rehype-code-blocks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-code-blocks.js","sources":["../../../src/plugins/rehype/rehype-code-blocks.ts"],"sourcesContent":["import { Plugin } from \"unified\";\nimport { Node, Element, ElementContent } from \"hast\";\nimport { visit } from \"unist-util-visit\";\nimport { MdxJsxFlowElement } from \"mdast-util-mdx-jsx\";\nimport { isElement } from \"../../utils/rehype\";\nimport type { BlockContent } from \"mdast\";\nimport type { Parent } from \"unist\";\nimport { refractor } from \"refractor\";\nimport { toString } from \"hast-util-to-string\";\n\nexport const rehypeCodeblocks: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, (node, index, parent) => {\n if (\n parent == null ||\n index == null ||\n !isElement(node) ||\n !isElement(node, \"tagName\", \"pre\")\n ) {\n return;\n }\n\n const code = node.children[0];\n\n if (!isElement(code, \"tagName\", \"code\")) return;\n\n const className = Array.isArray(code.properties?.className)\n ? (code.properties.className as string[]).join(\" \")\n : (code.properties?.className as string) || \"\";\n\n const m = className.match(/(?:language|lang)-(\\w+)/);\n const lang = m ? m[1] : undefined;\n\n if (lang) {\n try {\n const codeText = toString(code);\n const result = refractor.highlight(codeText, lang);\n\n if (!node.properties) {\n node.properties = {};\n }\n const preClassName = node.properties.className || [];\n const classArray = Array.isArray(preClassName)\n ? preClassName.filter(\n (c): c is string | number =>\n typeof c === \"string\" || typeof c === \"number\"\n )\n : [];\n node.properties.className = [...classArray, `language-${lang}`];\n\n (code as Element).children = result.children as ElementContent[];\n } catch (err) {\n console.warn(`Failed to highlight code for language \"${lang}\":`, err);\n }\n }\n\n const mdxNode: Node & MdxJsxFlowElement = {\n type: \"mdxJsxFlowElement\",\n name: \"CodeBlock\",\n attributes: [\n ...(lang\n ? [\n {\n type: \"mdxJsxAttribute\" as const,\n name: \"language\",\n value: lang,\n },\n ]\n : []),\n ],\n children: [],\n };\n\n mdxNode.children = [node as Node as BlockContent];\n\n if (parent && typeof index === \"number\") {\n (parent as Parent).children[index] = mdxNode;\n }\n });\n };\n};\n"],"names":["rehypeCodeblocks","tree","visit","node","index","parent","isElement","code","m","_a","_b","lang","codeText","toString","result","refractor","preClassName","classArray","c","err","mdxNode"],"mappings":";;;;AAUO,MAAMA,IAAqC,MACzC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,CAACE,GAAMC,GAAOC,MAAW;;AACnC,QACEA,KAAU,QACVD,KAAS,QACT,CAACE,EAAUH,CAAI,KACf,CAACG,EAAUH,GAAM,WAAW,KAAK;AAEjC;AAGF,UAAMI,IAAOJ,EAAK,SAAS,CAAC;AAE5B,QAAI,CAACG,EAAUC,GAAM,WAAW,MAAM,EAAG;AAMzC,UAAMC,KAJY,MAAM,SAAQC,IAAAF,EAAK,eAAL,gBAAAE,EAAiB,SAAS,IACrDF,EAAK,WAAW,UAAuB,KAAK,GAAG,MAC/CG,IAAAH,EAAK,eAAL,gBAAAG,EAAiB,cAAwB,IAE1B,MAAM,yBAAyB,GAC7CC,IAAOH,IAAIA,EAAE,CAAC,IAAI;AAExB,QAAIG;AACF,UAAI;AACF,cAAMC,IAAWC,EAASN,CAAI,GACxBO,IAASC,EAAU,UAAUH,GAAUD,CAAI;AAEjD,QAAKR,EAAK,eACRA,EAAK,aAAa,CAAA;AAEpB,cAAMa,IAAeb,EAAK,WAAW,aAAa,CAAA,GAC5Cc,IAAa,MAAM,QAAQD,CAAY,IACzCA,EAAa;AAAA,UACX,CAACE,MACC,OAAOA,KAAM,YAAY,OAAOA,KAAM;AAAA,QAAA,IAE1C,CAAA;AACJ,QAAAf,EAAK,WAAW,YAAY,CAAC,GAAGc,GAAY,YAAYN,CAAI,EAAE,GAE7DJ,EAAiB,WAAWO,EAAO;AAAA,MACtC,SAASK,GAAK;AACZ,gBAAQ,KAAK,0CAA0CR,CAAI,MAAMQ,CAAG;AAAA,MACtE;AAGF,UAAMC,IAAoC;AAAA,MACxC,MAAM;AAAA,MACN,MAAM;AAAA,MACN,YAAY;AAAA,QACV,GAAIT,IACA;AAAA,UACE;AAAA,YACE,MAAM;AAAA,YACN,MAAM;AAAA,YACN,OAAOA;AAAA,UAAA;AAAA,QACT,IAEF,CAAA;AAAA,MAAC;AAAA,MAEP,UAAU,CAAA;AAAA,IAAC;AAGb,IAAAS,EAAQ,WAAW,CAACjB,CAA4B,GAE5CE,KAAU,OAAOD,KAAU,aAC5BC,EAAkB,SAASD,CAAK,IAAIgB;AAAA,EAEzC,CAAC;AACH;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { visit as f } from "unist-util-visit";
|
|
2
|
+
import c from "@sindresorhus/slugify";
|
|
3
|
+
function d(a) {
|
|
4
|
+
return a.children.filter((i) => i.type === "text").map((i) => i.value).join("").replace(/\s*\([^)]*\)\s*/g, " ").trim();
|
|
5
|
+
}
|
|
6
|
+
function l() {
|
|
7
|
+
return (a) => {
|
|
8
|
+
f(a, "heading", (t) => {
|
|
9
|
+
var r, e;
|
|
10
|
+
const i = (e = (r = t.data) == null ? void 0 : r.hProperties) == null ? void 0 : e.id;
|
|
11
|
+
if (i)
|
|
12
|
+
t.data || (t.data = {}), t.data.hProperties || (t.data.hProperties = {}), t.data.hProperties.id = i;
|
|
13
|
+
else {
|
|
14
|
+
const s = d(t), p = c(s.replace(/\./g, "-"));
|
|
15
|
+
t.data || (t.data = {}), t.data.hProperties || (t.data.hProperties = {}), t.data.hProperties.id = p;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
l as remarkHeadingIds
|
|
22
|
+
};
|
|
23
|
+
//# sourceMappingURL=remark-heading-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remark-heading-ids.js","sources":["../../../src/plugins/remark/remark-heading-ids.ts"],"sourcesContent":["import type { Root } from \"mdast\";\nimport type { Heading } from \"mdast\";\nimport { visit } from \"unist-util-visit\";\nimport slugify from \"@sindresorhus/slugify\";\n\nfunction getHeadingText(node: Heading): string {\n const text = node.children\n .filter((child) => child.type === \"text\")\n .map((child) => (child as { value: string }).value)\n .join(\"\");\n\n return text.replace(/\\s*\\([^)]*\\)\\s*/g, \" \").trim();\n}\n\nexport function remarkHeadingIds() {\n return (tree: Root) => {\n\n visit(tree, \"heading\", (node: Heading) => {\n const existingId = node.data?.hProperties?.id;\n\n if (existingId) {\n if (!node.data) {\n node.data = {};\n }\n if (!node.data.hProperties) {\n node.data.hProperties = {};\n }\n node.data.hProperties.id = existingId;\n } else {\n const text = getHeadingText(node);\n const slug = slugify(text.replace(/\\./g, '-'));\n\n if (!node.data) {\n node.data = {};\n }\n if (!node.data.hProperties) {\n node.data.hProperties = {};\n }\n node.data.hProperties.id = slug;\n }\n });\n };\n}\n"],"names":["getHeadingText","node","child","remarkHeadingIds","tree","visit","existingId","_b","_a","text","slug","slugify"],"mappings":";;AAKA,SAASA,EAAeC,GAAuB;AAM7C,SALaA,EAAK,SACf,OAAO,CAACC,MAAUA,EAAM,SAAS,MAAM,EACvC,IAAI,CAACA,MAAWA,EAA4B,KAAK,EACjD,KAAK,EAAE,EAEE,QAAQ,oBAAoB,GAAG,EAAE,KAAA;AAC/C;AAEO,SAASC,IAAmB;AACjC,SAAO,CAACC,MAAe;AAErB,IAAAC,EAAMD,GAAM,WAAW,CAACH,MAAkB;;AACxC,YAAMK,KAAaC,KAAAC,IAAAP,EAAK,SAAL,gBAAAO,EAAW,gBAAX,gBAAAD,EAAwB;AAE3C,UAAID;AACF,QAAKL,EAAK,SACRA,EAAK,OAAO,CAAA,IAETA,EAAK,KAAK,gBACbA,EAAK,KAAK,cAAc,CAAA,IAE1BA,EAAK,KAAK,YAAY,KAAKK;AAAA,WACtB;AACL,cAAMG,IAAOT,EAAeC,CAAI,GAC1BS,IAAOC,EAAQF,EAAK,QAAQ,OAAO,GAAG,CAAC;AAE7C,QAAKR,EAAK,SACRA,EAAK,OAAO,CAAA,IAETA,EAAK,KAAK,gBACbA,EAAK,KAAK,cAAc,CAAA,IAE1BA,EAAK,KAAK,YAAY,KAAKS;AAAA,MAC7B;AAAA,IACF,CAAC;AAAA,EACH;AACF;"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { visit as p } from "unist-util-visit";
|
|
2
|
+
import { isElement as s, getClassNames as n } from "../../utils/rehype.js";
|
|
3
|
+
const i = {
|
|
4
|
+
NOTE: "note",
|
|
5
|
+
TIP: "tip",
|
|
6
|
+
IMPORTANT: "important",
|
|
7
|
+
CAUTION: "caution",
|
|
8
|
+
WARNING: "warning",
|
|
9
|
+
NEXTSTEPACTION: "nextstepaction"
|
|
10
|
+
};
|
|
11
|
+
function o(r) {
|
|
12
|
+
const t = r.toUpperCase();
|
|
13
|
+
return t in i ? t : null;
|
|
14
|
+
}
|
|
15
|
+
const c = () => (r) => {
|
|
16
|
+
p(r, (t) => {
|
|
17
|
+
if (!s(t) || !s(t, "tagName", "div")) return;
|
|
18
|
+
const a = n(t);
|
|
19
|
+
if (a.length === 0) return;
|
|
20
|
+
let e = null;
|
|
21
|
+
for (const l of a)
|
|
22
|
+
if (e = o(l), e) break;
|
|
23
|
+
e && (t.tagName = "Callout", t.properties = {
|
|
24
|
+
...t.properties,
|
|
25
|
+
type: i[e]
|
|
26
|
+
}, delete t.properties.className);
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
c as rehypeCallouts
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=rehype-callouts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-callouts.js","sources":["../../../src/plugins/sanitize/rehype-callouts.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Node } from \"hast\";\nimport { isElement, getClassNames } from \"../../utils/rehype\";\nimport { CalloutType } from \"../../components\";\n\nconst CALLOUT_CLASSES: Record<string, CalloutType> = {\n NOTE: \"note\",\n TIP: \"tip\",\n IMPORTANT: \"important\",\n CAUTION: \"caution\",\n WARNING: \"warning\",\n NEXTSTEPACTION: \"nextstepaction\",\n} as const;\n\ntype CalloutClass = keyof typeof CALLOUT_CLASSES;\n\nfunction extractCalloutType(className: string): CalloutClass | null {\n const upperClassName = className.toUpperCase();\n\n if (upperClassName in CALLOUT_CLASSES) {\n return upperClassName as CalloutClass;\n }\n\n return null;\n}\n\nexport const rehypeCallouts: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, (node) => {\n if (!isElement(node) || !isElement(node, \"tagName\", \"div\")) return;\n\n const classNames = getClassNames(node);\n if (classNames.length === 0) return;\n\n let calloutType: CalloutClass | null = null;\n\n for (const className of classNames) {\n calloutType = extractCalloutType(className);\n if (calloutType) break;\n }\n\n if (!calloutType) return;\n\n node.tagName = \"Callout\";\n node.properties = {\n ...node.properties,\n type: CALLOUT_CLASSES[calloutType],\n };\n delete node.properties.className;\n });\n };\n};\n"],"names":["CALLOUT_CLASSES","extractCalloutType","className","upperClassName","rehypeCallouts","tree","visit","node","isElement","classNames","getClassNames","calloutType"],"mappings":";;AAMA,MAAMA,IAA+C;AAAA,EACnD,MAAM;AAAA,EACN,KAAK;AAAA,EACL,WAAW;AAAA,EACX,SAAS;AAAA,EACT,SAAS;AAAA,EACT,gBAAgB;AAClB;AAIA,SAASC,EAAmBC,GAAwC;AAClE,QAAMC,IAAiBD,EAAU,YAAA;AAEjC,SAAIC,KAAkBH,IACbG,IAGF;AACT;AAEO,MAAMC,IAAmC,MACvC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,CAACE,MAAS;AACpB,QAAI,CAACC,EAAUD,CAAI,KAAK,CAACC,EAAUD,GAAM,WAAW,KAAK,EAAG;AAE5D,UAAME,IAAaC,EAAcH,CAAI;AACrC,QAAIE,EAAW,WAAW,EAAG;AAE7B,QAAIE,IAAmC;AAEvC,eAAWT,KAAaO;AAEtB,UADAE,IAAcV,EAAmBC,CAAS,GACtCS,EAAa;AAGnB,IAAKA,MAELJ,EAAK,UAAU,WACfA,EAAK,aAAa;AAAA,MAChB,GAAGA,EAAK;AAAA,MACR,MAAMP,EAAgBW,CAAW;AAAA,IAAA,GAEnC,OAAOJ,EAAK,WAAW;AAAA,EACzB,CAAC;AACH;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { visit as p } from "unist-util-visit";
|
|
2
|
+
const m = () => (i) => {
|
|
3
|
+
p(i, "element", (e) => {
|
|
4
|
+
var r, a;
|
|
5
|
+
if (e.tagName === "details") {
|
|
6
|
+
e.tagName = "Details";
|
|
7
|
+
const t = (r = e.properties) == null ? void 0 : r.open;
|
|
8
|
+
t !== void 0 && (e.properties = {
|
|
9
|
+
...e.properties,
|
|
10
|
+
open: t === !0 || t === ""
|
|
11
|
+
});
|
|
12
|
+
} else e.tagName === "summary" && (e.tagName = "Summary", (a = e.properties) == null || delete a.className);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
m as rehypeDetails
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=rehype-details.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-details.js","sources":["../../../src/plugins/sanitize/rehype-details.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Element, Node } from \"hast\";\n\nexport const rehypeDetails: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, \"element\", (node: Element) => {\n if (node.tagName === \"details\") {\n node.tagName = \"Details\";\n const openAttr = node.properties?.open;\n if (openAttr !== undefined) {\n node.properties = {\n ...node.properties,\n open: openAttr === true || openAttr === \"\",\n };\n }\n } else if (node.tagName === \"summary\") {\n node.tagName = \"Summary\";\n delete node.properties?.className;\n }\n });\n };\n};\n"],"names":["rehypeDetails","tree","visit","node","openAttr","_a","_b"],"mappings":";AAIO,MAAMA,IAAkC,MACtC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,WAAW,CAACE,MAAkB;;AACxC,QAAIA,EAAK,YAAY,WAAW;AAC9B,MAAAA,EAAK,UAAU;AACf,YAAMC,KAAWC,IAAAF,EAAK,eAAL,gBAAAE,EAAiB;AAClC,MAAID,MAAa,WACfD,EAAK,aAAa;AAAA,QAChB,GAAGA,EAAK;AAAA,QACR,MAAMC,MAAa,MAAQA,MAAa;AAAA,MAAA;AAAA,IAG9C,MAAA,CAAWD,EAAK,YAAY,cAC1BA,EAAK,UAAU,YACfG,IAAOH,EAAK,eAAZ,eAAAG,EAAwB;AAAA,EAE5B,CAAC;AACH;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { visit as s } from "unist-util-visit";
|
|
2
|
+
import { isElement as p } from "../../utils/rehype.js";
|
|
3
|
+
import { toString as o } from "hast-util-to-string";
|
|
4
|
+
import m from "@sindresorhus/slugify";
|
|
5
|
+
function f(r) {
|
|
6
|
+
return o(r).replace(/\s*\([^)]*\)\s*/g, " ").trim();
|
|
7
|
+
}
|
|
8
|
+
const l = () => (r) => {
|
|
9
|
+
s(r, (t) => {
|
|
10
|
+
if (p(t) && /^h[1-6]$/.test(t.tagName)) {
|
|
11
|
+
const e = f(t);
|
|
12
|
+
if (e) {
|
|
13
|
+
const i = m(e.replace(/\./g, "-"));
|
|
14
|
+
t.properties || (t.properties = {}), t.properties.id = i;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
export {
|
|
20
|
+
l as rehypeHeadingIds
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=rehype-heading-ids.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-heading-ids.js","sources":["../../../src/plugins/sanitize/rehype-heading-ids.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Node } from \"hast\";\nimport type { Element } from \"hast\";\nimport { isElement } from \"../../utils/rehype\";\nimport { toString } from \"hast-util-to-string\";\nimport slugify from \"@sindresorhus/slugify\";\n\nfunction getHeadingText(element: Element): string {\n const text = toString(element);\n return text.replace(/\\s*\\([^)]*\\)\\s*/g, \" \").trim();\n}\n\nexport const rehypeHeadingIds: Plugin<[], Node> = () => {\n return (tree: Node) => {\n visit(tree, (node) => {\n if (isElement(node) && /^h[1-6]$/.test(node.tagName)) {\n const text = getHeadingText(node);\n\n if (text) {\n const slug = slugify(text.replace(/\\./g, \"-\"));\n\n if (!node.properties) {\n node.properties = {};\n }\n node.properties.id = slug;\n }\n }\n });\n };\n};\n"],"names":["getHeadingText","element","toString","rehypeHeadingIds","tree","visit","node","isElement","text","slug","slugify"],"mappings":";;;;AAQA,SAASA,EAAeC,GAA0B;AAEhD,SADaC,EAASD,CAAO,EACjB,QAAQ,oBAAoB,GAAG,EAAE,KAAA;AAC/C;AAEO,MAAME,IAAqC,MACzC,CAACC,MAAe;AACrB,EAAAC,EAAMD,GAAM,CAACE,MAAS;AACpB,QAAIC,EAAUD,CAAI,KAAK,WAAW,KAAKA,EAAK,OAAO,GAAG;AACpD,YAAME,IAAOR,EAAeM,CAAI;AAEhC,UAAIE,GAAM;AACR,cAAMC,IAAOC,EAAQF,EAAK,QAAQ,OAAO,GAAG,CAAC;AAE7C,QAAKF,EAAK,eACRA,EAAK,aAAa,CAAA,IAEpBA,EAAK,WAAW,KAAKG;AAAA,MACvB;AAAA,IACF;AAAA,EACF,CAAC;AACH;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { visit as m } from "unist-util-visit";
|
|
2
|
+
import { isElement as a, getClassNames as s } from "../../utils/rehype.js";
|
|
3
|
+
const l = () => (r) => {
|
|
4
|
+
m(r, (e) => {
|
|
5
|
+
!a(e) || !a(e, "tagName", "div") || !s(e).includes("parameterName") || (e.tagName = "ParamName", delete e.properties.className);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
export {
|
|
9
|
+
l as rehypeParamName
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=rehype-param-name.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-param-name.js","sources":["../../../src/plugins/sanitize/rehype-param-name.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Node } from \"hast\";\nimport { isElement, getClassNames } from \"../../utils/rehype\";\n\nexport const rehypeParamName: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, (node) => {\n if (!isElement(node) || !isElement(node, \"tagName\", \"div\")) return;\n\n const classNames = getClassNames(node);\n if (!classNames.includes(\"parameterName\")) return;\n\n node.tagName = \"ParamName\";\n delete node.properties.className;\n });\n };\n};\n"],"names":["rehypeParamName","tree","visit","node","isElement","getClassNames"],"mappings":";;AAKO,MAAMA,IAAoC,MACxC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,CAACE,MAAS;AAIpB,IAHI,CAACC,EAAUD,CAAI,KAAK,CAACC,EAAUD,GAAM,WAAW,KAAK,KAGrD,CADeE,EAAcF,CAAI,EACrB,SAAS,eAAe,MAExCA,EAAK,UAAU,aACf,OAAOA,EAAK,WAAW;AAAA,EACzB,CAAC;AACH;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { visit as n } from "unist-util-visit";
|
|
2
|
+
import { isElement as t } from "../../utils/rehype.js";
|
|
3
|
+
const c = () => (p) => {
|
|
4
|
+
n(p, (a) => {
|
|
5
|
+
var o;
|
|
6
|
+
if (!t(a) || !t(a, "tagName", "pre"))
|
|
7
|
+
return;
|
|
8
|
+
const e = a.children[0];
|
|
9
|
+
if (!e || !t(e, "tagName", "code"))
|
|
10
|
+
return;
|
|
11
|
+
const i = (o = e.properties) == null ? void 0 : o.className;
|
|
12
|
+
if (Array.isArray(i)) {
|
|
13
|
+
for (const r of i)
|
|
14
|
+
if (typeof r == "string" && r.startsWith("lang-")) {
|
|
15
|
+
const s = r.replace(/^lang-/, "");
|
|
16
|
+
e.properties || (e.properties = {}), e.properties.className = [`language-${s}`];
|
|
17
|
+
break;
|
|
18
|
+
} else if (typeof r == "string" && r.startsWith("language-")) {
|
|
19
|
+
const s = r.replace(/^language-/, "");
|
|
20
|
+
e.properties || (e.properties = {}), e.properties.className = [`language-${s}`];
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
export {
|
|
27
|
+
c as sanitizePreTags
|
|
28
|
+
};
|
|
29
|
+
//# sourceMappingURL=rehype-pre-to-mdx-fence.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-pre-to-mdx-fence.js","sources":["../../../src/plugins/sanitize/rehype-pre-to-mdx-fence.ts"],"sourcesContent":["import { Plugin } from \"unified\";\nimport { Node, Element } from \"hast\";\nimport { visit } from \"unist-util-visit\";\nimport { isElement } from \"../../utils/rehype\";\n\nexport const sanitizePreTags: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, (node) => {\n if (!isElement(node) || !isElement(node, \"tagName\", \"pre\")) {\n return;\n }\n\n const code = node.children[0] as Element | undefined;\n if (!code || !isElement(code, \"tagName\", \"code\")) {\n return;\n }\n\n const className = code.properties?.className;\n if (Array.isArray(className)) {\n for (const cls of className) {\n if (typeof cls === \"string\" && cls.startsWith(\"lang-\")) {\n const lang = cls.replace(/^lang-/, \"\");\n if (!code.properties) code.properties = {};\n code.properties.className = [`language-${lang}`];\n break;\n } else if (typeof cls === \"string\" && cls.startsWith(\"language-\")) {\n const lang = cls.replace(/^language-/, \"\");\n if (!code.properties) code.properties = {};\n code.properties.className = [`language-${lang}`];\n break;\n }\n }\n }\n });\n };\n};\n"],"names":["sanitizePreTags","tree","visit","node","isElement","code","className","_a","cls","lang"],"mappings":";;AAKO,MAAMA,IAAoC,MACxC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,CAACE,MAAS;;AACpB,QAAI,CAACC,EAAUD,CAAI,KAAK,CAACC,EAAUD,GAAM,WAAW,KAAK;AACvD;AAGF,UAAME,IAAOF,EAAK,SAAS,CAAC;AAC5B,QAAI,CAACE,KAAQ,CAACD,EAAUC,GAAM,WAAW,MAAM;AAC7C;AAGF,UAAMC,KAAYC,IAAAF,EAAK,eAAL,gBAAAE,EAAiB;AACnC,QAAI,MAAM,QAAQD,CAAS;AACzB,iBAAWE,KAAOF;AAChB,YAAI,OAAOE,KAAQ,YAAYA,EAAI,WAAW,OAAO,GAAG;AACtD,gBAAMC,IAAOD,EAAI,QAAQ,UAAU,EAAE;AACrC,UAAKH,EAAK,eAAYA,EAAK,aAAa,CAAA,IACxCA,EAAK,WAAW,YAAY,CAAC,YAAYI,CAAI,EAAE;AAC/C;AAAA,QACF,WAAW,OAAOD,KAAQ,YAAYA,EAAI,WAAW,WAAW,GAAG;AACjE,gBAAMC,IAAOD,EAAI,QAAQ,cAAc,EAAE;AACzC,UAAKH,EAAK,eAAYA,EAAK,aAAa,CAAA,IACxCA,EAAK,WAAW,YAAY,CAAC,YAAYI,CAAI,EAAE;AAC/C;AAAA,QACF;AAAA;AAAA,EAGN,CAAC;AACH;"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defaultHandlers as m, toMdast as i } from "hast-util-to-mdast";
|
|
2
|
+
import { tableHandler as s, tableRowHandler as c, tableCellHandler as n } from "./rehype-table-align.js";
|
|
3
|
+
const d = [
|
|
4
|
+
"iframe",
|
|
5
|
+
"video",
|
|
6
|
+
"audio",
|
|
7
|
+
"svg",
|
|
8
|
+
"figure",
|
|
9
|
+
"figcaption",
|
|
10
|
+
"canvas",
|
|
11
|
+
"form",
|
|
12
|
+
"input"
|
|
13
|
+
], u = [
|
|
14
|
+
"Callout",
|
|
15
|
+
"ZonePivot",
|
|
16
|
+
"ZoneTarget",
|
|
17
|
+
"ParamName",
|
|
18
|
+
"Tabs",
|
|
19
|
+
"Tab",
|
|
20
|
+
"Details",
|
|
21
|
+
"Summary"
|
|
22
|
+
], f = [...d, ...u];
|
|
23
|
+
function o(e, t) {
|
|
24
|
+
const a = t.children ? e.all(t) : [];
|
|
25
|
+
return {
|
|
26
|
+
type: "mdxJsxFlowElement",
|
|
27
|
+
name: t.tagName,
|
|
28
|
+
attributes: Object.entries(t.properties ?? {}).map(([l, r]) => ({
|
|
29
|
+
type: "mdxJsxAttribute",
|
|
30
|
+
name: l,
|
|
31
|
+
value: Array.isArray(r) ? r.join(" ") : r
|
|
32
|
+
})),
|
|
33
|
+
children: a
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function x() {
|
|
37
|
+
const e = { ...m };
|
|
38
|
+
for (const t of f)
|
|
39
|
+
e[t] = o;
|
|
40
|
+
return e.mdxJsxFlowElement = o, e.table = s, e.tr = c, e.th = n, e.td = n, function(t) {
|
|
41
|
+
return i(t, {
|
|
42
|
+
handlers: e
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
export {
|
|
47
|
+
o as mdxJsxFlowElementHandler,
|
|
48
|
+
x as rehypeRemark
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=rehype-remark.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-remark.js","sources":["../../../src/plugins/sanitize/rehype-remark.ts"],"sourcesContent":["import { MdxJsxFlowElement } from \"mdast-util-mdx-jsx\";\nimport type { Root as HastRoot, Element } from \"hast\";\nimport { toMdast, defaultHandlers } from \"hast-util-to-mdast\";\nimport type { State, Handle } from \"hast-util-to-mdast\";\nimport type { Root as MdastRoot } from \"mdast\";\nimport type { BlockContent, DefinitionContent } from \"mdast\";\nimport {\n tableHandler,\n tableRowHandler,\n tableCellHandler,\n} from \"./rehype-table-align\";\n\nconst HTML_TAGS = [\n \"iframe\",\n \"video\",\n \"audio\",\n \"svg\",\n \"figure\",\n \"figcaption\",\n \"canvas\",\n \"form\",\n \"input\",\n];\nconst COMPONENT_NAMES = [\n \"Callout\",\n \"ZonePivot\",\n \"ZoneTarget\",\n \"ParamName\",\n \"Tabs\",\n \"Tab\",\n \"Details\",\n \"Summary\",\n];\nconst ALLOWED_COMPONENTS = [...HTML_TAGS, ...COMPONENT_NAMES];\n\nexport function mdxJsxFlowElementHandler(\n state: State,\n node: Element\n): MdxJsxFlowElement {\n const children = node.children\n ? (state.all(node) as Array<BlockContent | DefinitionContent>)\n : [];\n\n return {\n type: \"mdxJsxFlowElement\",\n name: node.tagName,\n attributes: Object.entries(node.properties ?? {}).map(([key, value]) => ({\n type: \"mdxJsxAttribute\",\n name: key,\n value: Array.isArray(value) ? value.join(\" \") : (value as string),\n })),\n children,\n };\n}\n\nexport function rehypeRemark() {\n const handlers: Record<string, Handle> = { ...defaultHandlers };\n\n for (const name of ALLOWED_COMPONENTS) {\n handlers[name] = mdxJsxFlowElementHandler;\n }\n handlers.mdxJsxFlowElement = mdxJsxFlowElementHandler;\n\n handlers.table = tableHandler;\n handlers.tr = tableRowHandler;\n handlers.th = tableCellHandler;\n handlers.td = tableCellHandler;\n\n return function (tree: HastRoot) {\n const newTree = toMdast(tree, {\n handlers,\n }) as MdastRoot;\n return newTree;\n };\n}\n"],"names":["HTML_TAGS","COMPONENT_NAMES","ALLOWED_COMPONENTS","mdxJsxFlowElementHandler","state","node","children","key","value","rehypeRemark","handlers","defaultHandlers","name","tableHandler","tableRowHandler","tableCellHandler","tree","toMdast"],"mappings":";;AAYA,MAAMA,IAAY;AAAA,EAChB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACMC,IAAkB;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GACMC,IAAqB,CAAC,GAAGF,GAAW,GAAGC,CAAe;AAErD,SAASE,EACdC,GACAC,GACmB;AACnB,QAAMC,IAAWD,EAAK,WACjBD,EAAM,IAAIC,CAAI,IACf,CAAA;AAEJ,SAAO;AAAA,IACL,MAAM;AAAA,IACN,MAAMA,EAAK;AAAA,IACX,YAAY,OAAO,QAAQA,EAAK,cAAc,EAAE,EAAE,IAAI,CAAC,CAACE,GAAKC,CAAK,OAAO;AAAA,MACvE,MAAM;AAAA,MACN,MAAMD;AAAA,MACN,OAAO,MAAM,QAAQC,CAAK,IAAIA,EAAM,KAAK,GAAG,IAAKA;AAAA,IAAA,EACjD;AAAA,IACF,UAAAF;AAAA,EAAA;AAEJ;AAEO,SAASG,IAAe;AAC7B,QAAMC,IAAmC,EAAE,GAAGC,EAAA;AAE9C,aAAWC,KAAQV;AACjB,IAAAQ,EAASE,CAAI,IAAIT;AAEnB,SAAAO,EAAS,oBAAoBP,GAE7BO,EAAS,QAAQG,GACjBH,EAAS,KAAKI,GACdJ,EAAS,KAAKK,GACdL,EAAS,KAAKK,GAEP,SAAUC,GAAgB;AAI/B,WAHgBC,EAAQD,GAAM;AAAA,MAC5B,UAAAN;AAAA,IAAA,CACD;AAAA,EAEH;AACF;"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { defaultHandlers as s } from "hast-util-to-mdast";
|
|
2
|
+
function f(l) {
|
|
3
|
+
var r;
|
|
4
|
+
if (!((r = l.properties) != null && r.style)) return null;
|
|
5
|
+
const n = String(l.properties.style).match(/text-align:\s*(left|center|right)/);
|
|
6
|
+
if (!n) return null;
|
|
7
|
+
const t = n[1];
|
|
8
|
+
return t === "left" ? "left" : t === "center" ? "center" : t === "right" ? "right" : null;
|
|
9
|
+
}
|
|
10
|
+
function h(l) {
|
|
11
|
+
const e = [];
|
|
12
|
+
if (!l.children) return e;
|
|
13
|
+
for (const n of l.children)
|
|
14
|
+
if (n.type === "element" && (n.tagName === "th" || n.tagName === "td")) {
|
|
15
|
+
const t = f(n);
|
|
16
|
+
e.push(t);
|
|
17
|
+
}
|
|
18
|
+
return e;
|
|
19
|
+
}
|
|
20
|
+
const u = (l, e) => {
|
|
21
|
+
const n = l.all(e);
|
|
22
|
+
let t;
|
|
23
|
+
if (e.children) {
|
|
24
|
+
for (const i of e.children)
|
|
25
|
+
if (i.type === "element" && i.tagName === "thead" && i.children) {
|
|
26
|
+
for (const c of i.children)
|
|
27
|
+
if (c.type === "element" && c.tagName === "tr") {
|
|
28
|
+
const a = h(c);
|
|
29
|
+
a.length > 0 && a.some((o) => o !== null) && (t = a);
|
|
30
|
+
break;
|
|
31
|
+
}
|
|
32
|
+
break;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const r = {
|
|
36
|
+
type: "table",
|
|
37
|
+
children: n
|
|
38
|
+
};
|
|
39
|
+
return t && t.length > 0 && (r.align = t), r;
|
|
40
|
+
}, d = (l, e) => {
|
|
41
|
+
var t, r;
|
|
42
|
+
return ((r = (t = s).tr) == null ? void 0 : r.call(t, l, e)) || { type: "tableRow", children: [] };
|
|
43
|
+
}, p = (l, e) => ({
|
|
44
|
+
type: "tableCell",
|
|
45
|
+
children: l.all(e)
|
|
46
|
+
});
|
|
47
|
+
export {
|
|
48
|
+
p as tableCellHandler,
|
|
49
|
+
u as tableHandler,
|
|
50
|
+
d as tableRowHandler
|
|
51
|
+
};
|
|
52
|
+
//# sourceMappingURL=rehype-table-align.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-table-align.js","sources":["../../../src/plugins/sanitize/rehype-table-align.ts"],"sourcesContent":["import type { Element } from \"hast\";\nimport type { State, Handle } from \"hast-util-to-mdast\";\nimport type { Table, TableRow, TableCell, AlignType, PhrasingContent } from \"mdast\";\nimport { defaultHandlers } from \"hast-util-to-mdast\";\n\nfunction getTextAlign(node: Element): AlignType | null {\n if (!node.properties?.style) return null;\n\n const style = String(node.properties.style);\n const textAlignMatch = style.match(/text-align:\\s*(left|center|right)/);\n\n if (!textAlignMatch) return null;\n\n const align = textAlignMatch[1];\n if (align === \"left\") return \"left\";\n if (align === \"center\") return \"center\";\n if (align === \"right\") return \"right\";\n\n return null;\n}\n\nfunction extractAlignFromRow(row: Element): (AlignType | null)[] {\n const aligns: (AlignType | null)[] = [];\n\n if (!row.children) return aligns;\n\n for (const child of row.children) {\n if (child.type === \"element\" && (child.tagName === \"th\" || child.tagName === \"td\")) {\n const align = getTextAlign(child);\n aligns.push(align);\n }\n }\n\n return aligns;\n}\n\nexport const tableHandler: Handle = (state: State, node: Element) => {\n const children = state.all(node);\n let align: (AlignType | null)[] | undefined;\n\n if (node.children) {\n for (const child of node.children) {\n if (\n child.type === \"element\" &&\n child.tagName === \"thead\" &&\n child.children\n ) {\n for (const headRow of child.children) {\n if (headRow.type === \"element\" && headRow.tagName === \"tr\") {\n const rowAligns = extractAlignFromRow(headRow);\n if (rowAligns.length > 0 && rowAligns.some((a) => a !== null)) {\n align = rowAligns;\n }\n break;\n }\n }\n break;\n }\n }\n }\n\n const table: Table = {\n type: \"table\",\n children: children as TableRow[],\n };\n\n if (align && align.length > 0) {\n table.align = align;\n }\n\n return table;\n};\n\nexport const tableRowHandler: Handle = (state: State, node: Element) => {\n const result = defaultHandlers.tr?.(state, node);\n return result || { type: \"tableRow\", children: [] };\n};\n\nexport const tableCellHandler: Handle = (state: State, node: Element) => {\n const children = state.all(node);\n\n const cell: TableCell = {\n type: \"tableCell\",\n children: children as PhrasingContent[],\n };\n\n return cell;\n};\n\n"],"names":["getTextAlign","node","_a","textAlignMatch","align","extractAlignFromRow","row","aligns","child","tableHandler","state","children","headRow","rowAligns","a","table","tableRowHandler","_b","defaultHandlers","tableCellHandler"],"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AAAgB,GAAgB,OAAhB,gBAAAD,EAAA,KAAAf,GAAqBQ,GAAOT,OAC1B,EAAE,MAAM,YAAY,UAAU,CAAA,EAAC;AAClD,GAEakB,IAA2B,CAACT,GAAcT,OAG7B;AAAA,EACtB,MAAM;AAAA,EACN,UAJeS,EAAM,IAAIT,CAAI;AAI7B;"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { visit as u, SKIP as b } from "unist-util-visit";
|
|
2
|
+
import { isElement as s, getClassNames as d, getTextContent as h } from "../../utils/rehype.js";
|
|
3
|
+
function N(c) {
|
|
4
|
+
var o, f, a, l;
|
|
5
|
+
const e = [], i = {};
|
|
6
|
+
for (const t of c.children)
|
|
7
|
+
if (s(t) && t.tagName === "ul" && ((o = t.properties) == null ? void 0 : o.role) === "tablist") {
|
|
8
|
+
for (const n of t.children)
|
|
9
|
+
if (!(!s(n) || n.tagName !== "li"))
|
|
10
|
+
for (const r of n.children) {
|
|
11
|
+
if (!s(r) || r.tagName !== "a") continue;
|
|
12
|
+
const m = (f = r.properties) == null ? void 0 : f.dataTab, p = h(r).trim();
|
|
13
|
+
m && p && (i[m] = p);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
for (const t of c.children)
|
|
17
|
+
if (s(t) && t.tagName === "section" && ((a = t.properties) == null ? void 0 : a.role) === "tabpanel") {
|
|
18
|
+
const n = (l = t.properties) == null ? void 0 : l.dataTab, r = i[n];
|
|
19
|
+
r && n && e.push({
|
|
20
|
+
title: r,
|
|
21
|
+
content: t.children,
|
|
22
|
+
dataTab: n
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return e.length > 0 ? e : null;
|
|
26
|
+
}
|
|
27
|
+
const y = () => (c) => {
|
|
28
|
+
u(c, "element", (e, i, o) => {
|
|
29
|
+
if (!s(e, "tagName", "div") || typeof i != "number" || !o || !d(e).includes("tabGroup")) return;
|
|
30
|
+
const a = N(e);
|
|
31
|
+
if (!a) return;
|
|
32
|
+
const l = {
|
|
33
|
+
type: "element",
|
|
34
|
+
tagName: "Tabs",
|
|
35
|
+
properties: {},
|
|
36
|
+
children: a.map((t) => ({
|
|
37
|
+
type: "element",
|
|
38
|
+
tagName: "Tab",
|
|
39
|
+
properties: {
|
|
40
|
+
title: t.title
|
|
41
|
+
},
|
|
42
|
+
children: t.content
|
|
43
|
+
}))
|
|
44
|
+
};
|
|
45
|
+
return o.children[i] = l, b;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
export {
|
|
49
|
+
y as rehypeTabs
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=rehype-tabs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-tabs.js","sources":["../../../src/plugins/sanitize/rehype-tabs.ts"],"sourcesContent":["import { visit, SKIP } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Element, Node, ElementContent } from \"hast\";\nimport { isElement, getClassNames, getTextContent } from \"../../utils/rehype\";\n\ninterface TabInfo {\n title: string;\n content: ElementContent[];\n dataTab: string;\n}\n\nfunction extractTabsFromGroup(node: Element): TabInfo[] | null {\n const tabs: TabInfo[] = [];\n const tabTitles: { [key: string]: string } = {};\n\n for (const child of node.children) {\n if (!isElement(child)) continue;\n\n if (child.tagName === \"ul\" && child.properties?.role === \"tablist\") {\n for (const li of child.children) {\n if (!isElement(li) || li.tagName !== \"li\") continue;\n\n for (const linkNode of li.children) {\n if (!isElement(linkNode) || linkNode.tagName !== \"a\") continue;\n\n const dataTab = linkNode.properties?.[\"dataTab\"] as string;\n const title = getTextContent(linkNode).trim();\n\n if (dataTab && title) {\n tabTitles[dataTab] = title;\n }\n }\n }\n }\n }\n\n for (const child of node.children) {\n if (!isElement(child)) continue;\n\n if (child.tagName === \"section\" && child.properties?.role === \"tabpanel\") {\n const dataTab = child.properties?.[\"dataTab\"] as string;\n const title = tabTitles[dataTab];\n\n if (title && dataTab) {\n tabs.push({\n title,\n content: child.children,\n dataTab,\n });\n }\n }\n }\n\n return tabs.length > 0 ? tabs : null;\n}\n\nexport const rehypeTabs: Plugin<[], Node> = () => {\n return (tree) => {\n visit(tree, \"element\", (node: Element, index, parent) => {\n if (!isElement(node, \"tagName\", \"div\")) return;\n if (typeof index !== \"number\" || !parent) return;\n\n const classNames = getClassNames(node);\n if (!classNames.includes(\"tabGroup\")) return;\n\n const tabs = extractTabsFromGroup(node);\n if (!tabs) return;\n\n const tabsElement: Element = {\n type: \"element\",\n tagName: \"Tabs\",\n properties: {},\n children: tabs.map((tab) => ({\n type: \"element\",\n tagName: \"Tab\",\n properties: {\n title: tab.title,\n },\n children: tab.content,\n })),\n };\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (parent as any).children[index] = tabsElement;\n\n return SKIP;\n });\n };\n};\n"],"names":["extractTabsFromGroup","node","tabs","tabTitles","child","isElement","_a","li","linkNode","dataTab","_b","title","getTextContent","_c","_d","rehypeTabs","tree","visit","index","parent","getClassNames","tabsElement","tab","SKIP"],"mappings":";;AAWA,SAASA,EAAqBC,GAAiC;;AAC7D,QAAMC,IAAkB,CAAA,GAClBC,IAAuC,CAAA;AAE7C,aAAWC,KAASH,EAAK;AACvB,QAAKI,EAAUD,CAAK,KAEhBA,EAAM,YAAY,UAAQE,IAAAF,EAAM,eAAN,gBAAAE,EAAkB,UAAS;AACvD,iBAAWC,KAAMH,EAAM;AACrB,YAAI,GAACC,EAAUE,CAAE,KAAKA,EAAG,YAAY;AAErC,qBAAWC,KAAYD,EAAG,UAAU;AAClC,gBAAI,CAACF,EAAUG,CAAQ,KAAKA,EAAS,YAAY,IAAK;AAEtD,kBAAMC,KAAUC,IAAAF,EAAS,eAAT,gBAAAE,EAAsB,SAChCC,IAAQC,EAAeJ,CAAQ,EAAE,KAAA;AAEvC,YAAIC,KAAWE,MACbR,EAAUM,CAAO,IAAIE;AAAA,UAEzB;AAAA;AAKN,aAAWP,KAASH,EAAK;AACvB,QAAKI,EAAUD,CAAK,KAEhBA,EAAM,YAAY,eAAaS,IAAAT,EAAM,eAAN,gBAAAS,EAAkB,UAAS,YAAY;AACxE,YAAMJ,KAAUK,IAAAV,EAAM,eAAN,gBAAAU,EAAmB,SAC7BH,IAAQR,EAAUM,CAAO;AAE/B,MAAIE,KAASF,KACXP,EAAK,KAAK;AAAA,QACR,OAAAS;AAAA,QACA,SAASP,EAAM;AAAA,QACf,SAAAK;AAAA,MAAA,CACD;AAAA,IAEL;AAGF,SAAOP,EAAK,SAAS,IAAIA,IAAO;AAClC;AAEO,MAAMa,IAA+B,MACnC,CAACC,MAAS;AACf,EAAAC,EAAMD,GAAM,WAAW,CAACf,GAAeiB,GAAOC,MAAW;AAKvD,QAJI,CAACd,EAAUJ,GAAM,WAAW,KAAK,KACjC,OAAOiB,KAAU,YAAY,CAACC,KAG9B,CADeC,EAAcnB,CAAI,EACrB,SAAS,UAAU,EAAG;AAEtC,UAAMC,IAAOF,EAAqBC,CAAI;AACtC,QAAI,CAACC,EAAM;AAEX,UAAMmB,IAAuB;AAAA,MAC3B,MAAM;AAAA,MACN,SAAS;AAAA,MACT,YAAY,CAAA;AAAA,MACZ,UAAUnB,EAAK,IAAI,CAACoB,OAAS;AAAA,QAC3B,MAAM;AAAA,QACN,SAAS;AAAA,QACT,YAAY;AAAA,UACV,OAAOA,EAAI;AAAA,QAAA;AAAA,QAEb,UAAUA,EAAI;AAAA,MAAA,EACd;AAAA,IAAA;AAIH,WAAAH,EAAe,SAASD,CAAK,IAAIG,GAE3BE;AAAA,EACT,CAAC;AACH;"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { visit as N } from "unist-util-visit";
|
|
2
|
+
import { isElement as f, getClassNames as w } from "../../utils/rehype.js";
|
|
3
|
+
import { toString as Z } from "hast-util-to-string";
|
|
4
|
+
function x(s) {
|
|
5
|
+
var c;
|
|
6
|
+
const o = ((c = s.properties) == null ? void 0 : c.id) || "", a = Z(s);
|
|
7
|
+
return o && a ? {
|
|
8
|
+
slug: o,
|
|
9
|
+
title: a,
|
|
10
|
+
level: 2
|
|
11
|
+
} : null;
|
|
12
|
+
}
|
|
13
|
+
function b(s) {
|
|
14
|
+
const o = [];
|
|
15
|
+
return N(s, (a) => {
|
|
16
|
+
if (f(a) && a.tagName === "h2") {
|
|
17
|
+
const c = x(a);
|
|
18
|
+
c && o.push(c);
|
|
19
|
+
}
|
|
20
|
+
}), o;
|
|
21
|
+
}
|
|
22
|
+
const C = (s) => {
|
|
23
|
+
const o = /* @__PURE__ */ new Set(), a = /* @__PURE__ */ new Map();
|
|
24
|
+
return (c) => {
|
|
25
|
+
var T;
|
|
26
|
+
const d = c.children || [];
|
|
27
|
+
for (let t = 0; t < d.length; t++) {
|
|
28
|
+
const e = d[t];
|
|
29
|
+
if (f(e) && e.tagName === "h2") {
|
|
30
|
+
const i = x(e);
|
|
31
|
+
if (!i) continue;
|
|
32
|
+
const g = /* @__PURE__ */ new Set();
|
|
33
|
+
for (let m = t + 1; m < d.length; m++) {
|
|
34
|
+
const n = d[m];
|
|
35
|
+
if (f(n) && n.tagName === "h2") break;
|
|
36
|
+
if (f(n) && n.tagName === "div") {
|
|
37
|
+
const u = w(n);
|
|
38
|
+
if (u.includes("zone") && u.includes("has-pivot")) {
|
|
39
|
+
const h = (T = n.properties) == null ? void 0 : T.dataPivot;
|
|
40
|
+
h && h.split(" ").map((p) => p.trim()).forEach((p) => g.add(p));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
a.set(i.slug, g);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
N(c, (t) => {
|
|
48
|
+
var m, n, u, h, p;
|
|
49
|
+
if (!f(t) || !f(t, "tagName", "div")) return;
|
|
50
|
+
const e = w(t);
|
|
51
|
+
if (!e.includes("zone")) return;
|
|
52
|
+
const i = e.includes("has-target"), g = e.includes("has-pivot");
|
|
53
|
+
if (g) {
|
|
54
|
+
const r = (m = t.properties) == null ? void 0 : m.dataPivot;
|
|
55
|
+
if (r) {
|
|
56
|
+
const v = r.split(" ").map((l) => l.trim());
|
|
57
|
+
v.forEach((l) => o.add(l)), b(t).forEach((l) => {
|
|
58
|
+
a.has(l.slug) || a.set(l.slug, /* @__PURE__ */ new Set()), v.forEach((G) => a.get(l.slug).add(G));
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (i && g) {
|
|
63
|
+
const r = (n = t.properties) == null ? void 0 : n.dataTarget, v = (u = t.properties) == null ? void 0 : u.dataPivot;
|
|
64
|
+
r && v && (t.tagName = "ZonePivot", t.properties = { pivot: v, target: r });
|
|
65
|
+
} else if (g) {
|
|
66
|
+
const r = (h = t.properties) == null ? void 0 : h.dataPivot;
|
|
67
|
+
r && (t.tagName = "ZonePivot", t.properties = { pivot: r });
|
|
68
|
+
} else if (i) {
|
|
69
|
+
const r = (p = t.properties) == null ? void 0 : p.dataTarget;
|
|
70
|
+
r && (t.tagName = "ZoneTarget", t.properties = { target: r });
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
const S = [], z = /* @__PURE__ */ new Set();
|
|
74
|
+
N(c, (t) => {
|
|
75
|
+
if (f(t) && t.tagName === "h2") {
|
|
76
|
+
const e = x(t);
|
|
77
|
+
e && !z.has(e.slug) && (z.add(e.slug), a.has(e.slug) || a.set(e.slug, /* @__PURE__ */ new Set()), S.push(e));
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
const P = {};
|
|
81
|
+
if (o.forEach((t) => {
|
|
82
|
+
P[t] = S.filter((e) => {
|
|
83
|
+
const i = a.get(e.slug);
|
|
84
|
+
return i && (i.has(t) || i.size === 0);
|
|
85
|
+
});
|
|
86
|
+
}), !(s != null && s.metadata) || !(s != null && s.mdxExtracts) || o.size === 0) return;
|
|
87
|
+
const E = s.metadata.zonePivots, I = s.metadata.zone_pivot_groups;
|
|
88
|
+
if (E != null && E.groups) {
|
|
89
|
+
let t = E.groups;
|
|
90
|
+
if (I) {
|
|
91
|
+
const e = I.split(",").map((i) => i.trim()).filter(Boolean);
|
|
92
|
+
e.length > 0 && (t = t.filter(
|
|
93
|
+
(i) => e.includes(i.id)
|
|
94
|
+
));
|
|
95
|
+
}
|
|
96
|
+
t = t.filter(
|
|
97
|
+
(e) => e.pivots.some((i) => o.has(i.id))
|
|
98
|
+
), t.length > 0 && (s.mdxExtracts.zonePivotGroups = t);
|
|
99
|
+
}
|
|
100
|
+
Object.keys(P).length > 0 && (s.mdxExtracts.pivotTocItems = P);
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
export {
|
|
104
|
+
C as rehypeZonePivots
|
|
105
|
+
};
|
|
106
|
+
//# sourceMappingURL=rehype-zone-pivots.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rehype-zone-pivots.js","sources":["../../../src/plugins/sanitize/rehype-zone-pivots.ts"],"sourcesContent":["import { visit } from \"unist-util-visit\";\nimport type { Plugin } from \"unified\";\nimport type { Node } from \"hast\";\nimport type { Element } from \"hast\";\nimport { isElement, getClassNames } from \"../../utils/rehype\";\nimport type { ConvertOptions, TocItem } from \"../../types\";\nimport { toString } from \"hast-util-to-string\";\n\ninterface RawZonePivotGroup {\n id: string;\n title: string;\n prompt: string;\n pivots: Array<{\n id: string;\n title: string;\n }>;\n}\n\ninterface RawZonePivots {\n groups?: RawZonePivotGroup[];\n}\n\nfunction extractH2FromElement(element: Element): TocItem | null {\n const id = (element.properties?.id as string) || \"\";\n const text = toString(element);\n\n if (id && text) {\n return {\n slug: id,\n title: text,\n level: 2,\n };\n }\n\n return null;\n}\n\nfunction extractH2Elements(node: Element): TocItem[] {\n const tocItems: TocItem[] = [];\n\n visit(node, (child) => {\n if (isElement(child) && child.tagName === \"h2\") {\n const tocItem = extractH2FromElement(child);\n if (tocItem) {\n tocItems.push(tocItem);\n }\n }\n });\n\n return tocItems;\n}\n\nexport const rehypeZonePivots: Plugin<[ConvertOptions?], Node> = (\n options?: ConvertOptions\n) => {\n const usedPivotIds = new Set<string>();\n const h2ToPivots = new Map<string, Set<string>>();\n\n return (tree) => {\n const rootChildren = ((tree as any).children || []) as Node[];\n\n for (let i = 0; i < rootChildren.length; i++) {\n const node = rootChildren[i];\n\n if (isElement(node) && node.tagName === \"h2\") {\n const h2 = extractH2FromElement(node);\n if (!h2) continue;\n\n const associatedPivots = new Set<string>();\n\n for (let j = i + 1; j < rootChildren.length; j++) {\n const sibling = rootChildren[j];\n\n if (isElement(sibling) && sibling.tagName === \"h2\") break;\n\n if (isElement(sibling) && sibling.tagName === \"div\") {\n const classNames = getClassNames(sibling);\n if (classNames.includes(\"zone\") && classNames.includes(\"has-pivot\")) {\n const pivot = sibling.properties?.dataPivot as string | undefined;\n if (pivot) {\n pivot.split(\" \").map((p) => p.trim()).forEach((id) => associatedPivots.add(id));\n }\n }\n }\n }\n\n h2ToPivots.set(h2.slug, associatedPivots);\n }\n }\n\n visit(tree, (node) => {\n if (!isElement(node) || !isElement(node, \"tagName\", \"div\")) return;\n\n const classNames = getClassNames(node);\n if (!classNames.includes(\"zone\")) return;\n\n const hasTarget = classNames.includes(\"has-target\");\n const hasPivot = classNames.includes(\"has-pivot\");\n\n if (hasPivot) {\n const pivot = node.properties?.dataPivot as string | undefined;\n if (pivot) {\n const pivotIds = pivot.split(\" \").map((p) => p.trim());\n pivotIds.forEach((id) => usedPivotIds.add(id));\n\n const h2Elements = extractH2Elements(node);\n h2Elements.forEach((h2) => {\n if (!h2ToPivots.has(h2.slug)) {\n h2ToPivots.set(h2.slug, new Set());\n }\n pivotIds.forEach((id) => h2ToPivots.get(h2.slug)!.add(id));\n });\n }\n }\n\n if (hasTarget && hasPivot) {\n const target = node.properties?.dataTarget as string | undefined;\n const pivot = node.properties?.dataPivot as string | undefined;\n if (target && pivot) {\n node.tagName = \"ZonePivot\";\n node.properties = { pivot, target };\n }\n } else if (hasPivot) {\n const pivot = node.properties?.dataPivot as string | undefined;\n if (pivot) {\n node.tagName = \"ZonePivot\";\n node.properties = { pivot };\n }\n } else if (hasTarget) {\n const target = node.properties?.dataTarget as string | undefined;\n if (target) {\n node.tagName = \"ZoneTarget\";\n node.properties = { target };\n }\n }\n });\n\n const allH2s: TocItem[] = [];\n const seenSlugs = new Set<string>();\n\n visit(tree, (node) => {\n if (isElement(node) && node.tagName === \"h2\") {\n const h2 = extractH2FromElement(node);\n if (h2 && !seenSlugs.has(h2.slug)) {\n seenSlugs.add(h2.slug);\n if (!h2ToPivots.has(h2.slug)) {\n h2ToPivots.set(h2.slug, new Set());\n }\n allH2s.push(h2);\n }\n }\n });\n\n const pivotTocItems: Record<string, TocItem[]> = {};\n usedPivotIds.forEach((pivotId) => {\n pivotTocItems[pivotId] = allH2s.filter((h2) => {\n const pivotIds = h2ToPivots.get(h2.slug);\n return pivotIds && (pivotIds.has(pivotId) || pivotIds.size === 0);\n });\n });\n\n if (!options?.metadata || !options?.mdxExtracts || usedPivotIds.size === 0) return;\n\n const zonePivots = options.metadata.zonePivots as RawZonePivots | undefined;\n const zonePivotGroupsString = options.metadata.zone_pivot_groups as string | undefined;\n\n if (zonePivots?.groups) {\n let relevantGroups = zonePivots.groups;\n\n if (zonePivotGroupsString) {\n const activeGroupIds = zonePivotGroupsString\n .split(\",\")\n .map((id) => id.trim())\n .filter(Boolean);\n\n if (activeGroupIds.length > 0) {\n relevantGroups = relevantGroups.filter((group) =>\n activeGroupIds.includes(group.id)\n );\n }\n }\n\n relevantGroups = relevantGroups.filter((group) =>\n group.pivots.some((pivot) => usedPivotIds.has(pivot.id))\n );\n\n if (relevantGroups.length > 0) {\n options.mdxExtracts.zonePivotGroups = relevantGroups;\n }\n }\n\n if (Object.keys(pivotTocItems).length > 0) {\n options.mdxExtracts.pivotTocItems = pivotTocItems;\n }\n };\n};\n"],"names":["extractH2FromElement","element","id","_a","text","toString","extractH2Elements","node","tocItems","visit","child","isElement","tocItem","rehypeZonePivots","options","usedPivotIds","h2ToPivots","tree","rootChildren","i","h2","associatedPivots","j","sibling","classNames","getClassNames","pivot","hasTarget","hasPivot","pivotIds","p","target","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1B,EAAQ,SAAS,YAC9B2B,IAAwB3B,EAAQ,SAAS;AAE/C,QAAI0B,KAAA,QAAAA,EAAY,QAAQ;AACtB,UAAIE,IAAiBF,EAAW;AAEhC,UAAIC,GAAuB;AACzB,cAAME,IAAiBF,EACpB,MAAM,GAAG,EACT,IAAI,CAACvC,MAAOA,EAAG,KAAA,CAAM,EACrB,OAAO,OAAO;AAEjB,QAAIyC,EAAe,SAAS,MAC1BD,IAAiBA,EAAe;AAAA,UAAO,CAACE,MACtCD,EAAe,SAASC,EAAM,EAAE;AAAA,QAAA;AAAA,MAGtC;AAEA,MAAAF,IAAiBA,EAAe;AAAA,QAAO,CAACE,MACtCA,EAAM,OAAO,KAAK,CAAClB,MAAUX,EAAa,IAAIW,EAAM,EAAE,CAAC;AAAA,MAAA,GAGrDgB,EAAe,SAAS,MAC1B5B,EAAQ,YAAY,kBAAkB4B;AAAA,IAE1C;AAEA,IAAI,OAAO,KAAKJ,CAAa,EAAE,SAAS,MACtCxB,EAAQ,YAAY,gBAAgBwB;AAAA,EAExC;AACF;"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { visit as n, CONTINUE as o } from "unist-util-visit";
|
|
2
|
+
function r(t) {
|
|
3
|
+
n(t, "comment", function(i, e, m) {
|
|
4
|
+
if (m && typeof e == "number")
|
|
5
|
+
return m.children.splice(e, 1), [o, e];
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function c() {
|
|
9
|
+
return function(t) {
|
|
10
|
+
return r(t);
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export {
|
|
14
|
+
c as rehypeRemoveHtmlComments,
|
|
15
|
+
r as removeHtmlComments
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=remove-html-comments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-html-comments.js","sources":["../../../src/plugins/sanitize/remove-html-comments.ts"],"sourcesContent":["import type { Root as HastRoot } from \"hast\";\nimport { visit, CONTINUE } from \"unist-util-visit\";\n\nexport function removeHtmlComments(root: HastRoot): void {\n visit(root, \"comment\", function (_, index, parent) {\n if (parent && typeof index === \"number\") {\n parent.children.splice(index, 1);\n return [CONTINUE, index];\n }\n });\n}\n\nexport function rehypeRemoveHtmlComments() {\n return function (root: HastRoot) {\n return removeHtmlComments(root);\n };\n}\n"],"names":["removeHtmlComments","root","visit","_","index","parent","CONTINUE","rehypeRemoveHtmlComments"],"mappings":";AAGO,SAASA,EAAmBC,GAAsB;AACvD,EAAAC,EAAMD,GAAM,WAAW,SAAUE,GAAGC,GAAOC,GAAQ;AACjD,QAAIA,KAAU,OAAOD,KAAU;AAC7B,aAAAC,EAAO,SAAS,OAAOD,GAAO,CAAC,GACxB,CAACE,GAAUF,CAAK;AAAA,EAE3B,CAAC;AACH;AAEO,SAASG,IAA2B;AACzC,SAAO,SAAUN,GAAgB;AAC/B,WAAOD,EAAmBC,CAAI;AAAA,EAChC;AACF;"}
|