@mintlify/common 1.0.41 → 1.0.43

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.
Files changed (66) hide show
  1. package/dist/index.d.ts +3 -2
  2. package/dist/index.js +3 -2
  3. package/dist/mdx/getMDXOptions.d.ts +3 -0
  4. package/dist/mdx/getMDXOptions.js +32 -0
  5. package/dist/mdx/index.d.ts +3 -0
  6. package/dist/mdx/index.js +3 -0
  7. package/dist/mdx/lib/findExportedNode.d.ts +2 -0
  8. package/dist/mdx/lib/findExportedNode.js +30 -0
  9. package/dist/mdx/lib/index.d.ts +3 -0
  10. package/dist/mdx/lib/index.js +3 -0
  11. package/dist/mdx/lib/mdx-utils.d.ts +8 -0
  12. package/dist/mdx/lib/mdx-utils.js +8 -0
  13. package/dist/mdx/lib/remark-utils.d.ts +13 -0
  14. package/dist/mdx/lib/remark-utils.js +136 -0
  15. package/dist/mdx/plugins/index.d.ts +2 -0
  16. package/dist/mdx/plugins/index.js +2 -0
  17. package/dist/mdx/plugins/rehype/index.d.ts +8 -0
  18. package/dist/mdx/plugins/rehype/index.js +8 -0
  19. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.d.ts +4 -0
  20. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +44 -0
  21. package/dist/mdx/plugins/rehype/rehypeLayouts.d.ts +1 -0
  22. package/dist/mdx/plugins/rehype/rehypeLayouts.js +133 -0
  23. package/dist/mdx/plugins/rehype/rehypeListRoles.d.ts +1 -0
  24. package/dist/mdx/plugins/rehype/rehypeListRoles.js +10 -0
  25. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -0
  26. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +64 -0
  27. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.d.ts +3 -0
  28. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.js +9 -0
  29. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.d.ts +3 -0
  30. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.js +93 -0
  31. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.d.ts +17 -0
  32. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.js +83 -0
  33. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.d.ts +24 -0
  34. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.js +251 -0
  35. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +15 -0
  36. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.js +20 -0
  37. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +5 -0
  38. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js +18 -0
  39. package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +1 -0
  40. package/dist/mdx/plugins/rehype/rehypeRawComponents.js +12 -0
  41. package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -0
  42. package/dist/mdx/plugins/rehype/rehypeZoomImages.js +15 -0
  43. package/dist/mdx/plugins/remark/index.d.ts +7 -0
  44. package/dist/mdx/plugins/remark/index.js +7 -0
  45. package/dist/mdx/plugins/remark/remarkFrames.d.ts +1 -0
  46. package/dist/mdx/plugins/remark/remarkFrames.js +37 -0
  47. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.d.ts +3 -0
  48. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.js +23 -0
  49. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +3 -0
  50. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +26 -0
  51. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.d.ts +2 -0
  52. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.js +20 -0
  53. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.d.ts +2 -0
  54. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.js +28 -0
  55. package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -0
  56. package/dist/mdx/plugins/remark/remarkRemoveImports.js +11 -0
  57. package/dist/mdx/plugins/remark/remarkTableOfContents.d.ts +1 -0
  58. package/dist/mdx/plugins/remark/remarkTableOfContents.js +57 -0
  59. package/dist/topologicalSort.d.ts +4 -0
  60. package/dist/topologicalSort.js +19 -0
  61. package/dist/tsconfig.build.tsbuildinfo +1 -1
  62. package/dist/types/mdx/UserDefinedExampleData.d.ts +15 -0
  63. package/dist/types/mdx/UserDefinedExampleData.js +1 -0
  64. package/dist/types/mdx/index.d.ts +1 -0
  65. package/dist/types/mdx/index.js +1 -0
  66. package/package.json +23 -3
@@ -0,0 +1,26 @@
1
+ import { removePosition } from 'unist-util-remove-position';
2
+ import { visit, SKIP } from 'unist-util-visit';
3
+ export const remarkMdxInjectSnippets = (snippetTreeMap) => {
4
+ return (tree, file) => {
5
+ visit(tree, (node, index, parent) => {
6
+ if (parent && index !== null && node.type === 'mdxJsxFlowElement') {
7
+ const mdxJsxFlowElement = node;
8
+ if (mdxJsxFlowElement.name === 'Snippet') {
9
+ const fileAttr = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'file');
10
+ const name = fileAttr === null || fileAttr === void 0 ? void 0 : fileAttr.value;
11
+ if (typeof name === 'string') {
12
+ const snippet = snippetTreeMap[name];
13
+ if (snippet) {
14
+ const fragment = removePosition(structuredClone(snippet));
15
+ parent.children.splice(index, 1, ...fragment.children);
16
+ return [SKIP, index];
17
+ }
18
+ else {
19
+ file.message('Cannot expand missing snippet `' + name + '`', node, 'remark-mdx-inject-snippets');
20
+ }
21
+ }
22
+ }
23
+ }
24
+ });
25
+ };
26
+ };
@@ -0,0 +1,2 @@
1
+ import type { Node } from 'unist';
2
+ export declare const remarkMdxRemoveJs: () => (tree: Node) => void;
@@ -0,0 +1,20 @@
1
+ import { remove } from 'unist-util-remove';
2
+ import { findExportedNodes } from '../../../lib/index.js';
3
+ import { estreeIsProgram } from '../../../utils.js';
4
+ export const remarkMdxRemoveJs = () => (tree) => {
5
+ const exportedVariables = findExportedNodes(tree, 'Literal', 'JSXElement');
6
+ remove(tree, (node) => {
7
+ if (!nodeIsMdxFlowExpression(node) || !estreeIsProgram(node))
8
+ return false;
9
+ if (node.data.estree.body[0] == undefined || node.data.estree.body.length > 1)
10
+ return false;
11
+ if (node.data.estree.body[0].type !== 'ExpressionStatement')
12
+ return false;
13
+ if (node.data.estree.body[0].expression.type !== 'Identifier')
14
+ return false;
15
+ if (exportedVariables.includes(node.data.estree.body[0].expression.name))
16
+ return false;
17
+ return true;
18
+ });
19
+ };
20
+ const nodeIsMdxFlowExpression = (node) => node.type === 'mdxFlowExpression';
@@ -0,0 +1,2 @@
1
+ import type { Parent } from 'unist';
2
+ export declare const remarkMdxWrapDangerouslySetInnerHtml: () => (tree: Parent) => void;
@@ -0,0 +1,28 @@
1
+ import { visit } from 'unist-util-visit';
2
+ export const remarkMdxWrapDangerouslySetInnerHtml = () => {
3
+ return (tree) => {
4
+ visit(tree, (node, i, parent) => {
5
+ if (node.type === 'mdxJsxFlowElement') {
6
+ const mdxJsxFlowElement = node;
7
+ const attributesExist = mdxJsxFlowElement.attributes.length >= 1;
8
+ if (mdxJsxFlowElement.name === 'div' && attributesExist) {
9
+ const dangerouslySetInnerHTML = mdxJsxFlowElement.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'dangerouslySetInnerHTML');
10
+ if (dangerouslySetInnerHTML &&
11
+ dangerouslySetInnerHTML.value &&
12
+ typeof dangerouslySetInnerHTML.value === 'object' &&
13
+ dangerouslySetInnerHTML.value.value.includes('quartoRawHtml')) {
14
+ const wrap = {
15
+ type: 'mdxJsxFlowElement',
16
+ name: 'DynamicCustomComponent',
17
+ attributes: [],
18
+ data: { _mdxExplicitJsx: true },
19
+ children: [node],
20
+ };
21
+ if (parent && i)
22
+ parent.children[i] = wrap;
23
+ }
24
+ }
25
+ }
26
+ });
27
+ };
28
+ };
@@ -0,0 +1,2 @@
1
+ import type { Node } from 'unist';
2
+ export declare const remarkRemoveImports: () => <T extends Node<import("unist").Data>>(tree: T) => T;
@@ -0,0 +1,11 @@
1
+ import { remove } from 'unist-util-remove';
2
+ export const remarkRemoveImports = () => (tree) => {
3
+ remove(tree, (node) => {
4
+ if (node.type === 'mdxjsEsm') {
5
+ const mdxjsEsm = node;
6
+ return mdxjsEsm.value.startsWith('import');
7
+ }
8
+ return false;
9
+ });
10
+ return tree;
11
+ };
@@ -0,0 +1 @@
1
+ export function remarkTableOfContents(): (tree: any) => void;
@@ -0,0 +1,57 @@
1
+ import { slugifyWithCounter } from '@sindresorhus/slugify';
2
+ import { addExport, createMdxJsxAttribute } from '../../lib/remark-utils.js';
3
+ const getTOCTitle = (node, i = 1, a = []) => {
4
+ var _a, _b;
5
+ if ((node.type === 'text' &&
6
+ (((_a = a[i - 1]) === null || _a === void 0 ? void 0 : _a.type) !== 'mdxJsxFlowElement' || !((_b = a[i - 1]) === null || _b === void 0 ? void 0 : _b.value.startsWith('<small')))) ||
7
+ node.type === 'inlineCode') {
8
+ return node.value;
9
+ }
10
+ if (node.children) {
11
+ let title = '';
12
+ node.children.forEach((node, i, a) => {
13
+ title += getTOCTitle(node, i, a);
14
+ });
15
+ return title;
16
+ }
17
+ return '';
18
+ };
19
+ export const remarkTableOfContents = () => {
20
+ // slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
21
+ // already exists. No counter is added for the first occurence.
22
+ const slugify = slugifyWithCounter();
23
+ return (tree) => {
24
+ const contents = [];
25
+ let hasTopLayer = false;
26
+ for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
27
+ let node = tree.children[nodeIndex];
28
+ if ((node.type === 'heading' && [1, 2, 3, 4].includes(node.depth)) ||
29
+ (node.type === 'mdxJsxFlowElement' && ['h1', 'h2', 'h3', 'h4'].includes(node.name))) {
30
+ let level = node.depth ? node.depth : node.name.split('')[1];
31
+ let title = getTOCTitle(node);
32
+ const slug = slugify(title, { decamelize: false });
33
+ let mdxJsxAttributes = [
34
+ createMdxJsxAttribute('level', level),
35
+ createMdxJsxAttribute('id', slug),
36
+ ];
37
+ node.attributes = mdxJsxAttributes;
38
+ node.type = 'mdxJsxFlowElement';
39
+ node.name = 'Heading';
40
+ const depth = node.depth;
41
+ if (level <= 2) {
42
+ hasTopLayer = true;
43
+ contents.push({ title, slug, depth, children: [] });
44
+ }
45
+ else {
46
+ // Account if there is no first layer
47
+ let arrToPushInto = contents;
48
+ if (hasTopLayer) {
49
+ arrToPushInto = contents[contents.length - 1].children;
50
+ }
51
+ arrToPushInto.push({ title, slug, depth, children: [] });
52
+ }
53
+ }
54
+ }
55
+ addExport(tree, 'tableOfContents', contents);
56
+ };
57
+ };
@@ -0,0 +1,4 @@
1
+ export type Graph = {
2
+ [key: string]: string[];
3
+ };
4
+ export declare function topologicalSort(graph: Graph): string[];
@@ -0,0 +1,19 @@
1
+ export function topologicalSort(graph) {
2
+ const visited = new Set();
3
+ const stack = [];
4
+ function dfs(node) {
5
+ visited.add(node);
6
+ for (const neighbor of graph[node] || []) {
7
+ if (!visited.has(neighbor)) {
8
+ dfs(neighbor);
9
+ }
10
+ }
11
+ stack.push(node);
12
+ }
13
+ for (const node in graph) {
14
+ if (!visited.has(node)) {
15
+ dfs(node);
16
+ }
17
+ }
18
+ return stack.reverse();
19
+ }