@mintlify/common 1.0.42 → 1.0.44

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 (65) hide show
  1. package/dist/mdx/getMDXOptions.d.ts +3 -0
  2. package/dist/mdx/getMDXOptions.js +32 -0
  3. package/dist/mdx/index.d.ts +3 -0
  4. package/dist/mdx/index.js +3 -0
  5. package/dist/mdx/lib/findExportedNode.d.ts +2 -0
  6. package/dist/mdx/lib/findExportedNode.js +30 -0
  7. package/dist/mdx/lib/index.d.ts +3 -0
  8. package/dist/mdx/lib/index.js +3 -0
  9. package/dist/mdx/lib/mdx-utils.d.ts +8 -0
  10. package/dist/mdx/lib/mdx-utils.js +8 -0
  11. package/dist/mdx/lib/remark-utils.d.ts +13 -0
  12. package/dist/mdx/lib/remark-utils.js +136 -0
  13. package/dist/mdx/plugins/index.d.ts +2 -0
  14. package/dist/mdx/plugins/index.js +2 -0
  15. package/dist/mdx/plugins/rehype/index.d.ts +8 -0
  16. package/dist/mdx/plugins/rehype/index.js +8 -0
  17. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.d.ts +4 -0
  18. package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +44 -0
  19. package/dist/mdx/plugins/rehype/rehypeLayouts.d.ts +1 -0
  20. package/dist/mdx/plugins/rehype/rehypeLayouts.js +133 -0
  21. package/dist/mdx/plugins/rehype/rehypeListRoles.d.ts +1 -0
  22. package/dist/mdx/plugins/rehype/rehypeListRoles.js +10 -0
  23. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -0
  24. package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +64 -0
  25. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.d.ts +3 -0
  26. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.js +9 -0
  27. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.d.ts +3 -0
  28. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.js +93 -0
  29. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.d.ts +17 -0
  30. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.js +83 -0
  31. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.d.ts +24 -0
  32. package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.js +251 -0
  33. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +15 -0
  34. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.js +20 -0
  35. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +5 -0
  36. package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js +18 -0
  37. package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +1 -0
  38. package/dist/mdx/plugins/rehype/rehypeRawComponents.js +12 -0
  39. package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -0
  40. package/dist/mdx/plugins/rehype/rehypeZoomImages.js +15 -0
  41. package/dist/mdx/plugins/remark/index.d.ts +7 -0
  42. package/dist/mdx/plugins/remark/index.js +7 -0
  43. package/dist/mdx/plugins/remark/remarkFrames.d.ts +1 -0
  44. package/dist/mdx/plugins/remark/remarkFrames.js +37 -0
  45. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.d.ts +3 -0
  46. package/dist/mdx/plugins/remark/remarkMdxInjectRequire.js +23 -0
  47. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +3 -0
  48. package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +26 -0
  49. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.d.ts +2 -0
  50. package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.js +20 -0
  51. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.d.ts +2 -0
  52. package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.js +28 -0
  53. package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -0
  54. package/dist/mdx/plugins/remark/remarkRemoveImports.js +11 -0
  55. package/dist/mdx/plugins/remark/remarkTableOfContents.d.ts +1 -0
  56. package/dist/mdx/plugins/remark/remarkTableOfContents.js +57 -0
  57. package/dist/mdx/snippets/resolveImport/resolveComponentWithContent.js +60 -3
  58. package/dist/mdx/utils.d.ts +1 -0
  59. package/dist/mdx/utils.js +1 -0
  60. package/dist/tsconfig.build.tsbuildinfo +1 -1
  61. package/dist/types/mdx/UserDefinedExampleData.d.ts +15 -0
  62. package/dist/types/mdx/UserDefinedExampleData.js +1 -0
  63. package/dist/types/mdx/index.d.ts +1 -0
  64. package/dist/types/mdx/index.js +1 -0
  65. package/package.json +24 -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
+ };
@@ -7,11 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ import { walk } from 'estree-walker';
10
11
  import matter from 'gray-matter';
11
12
  import { remark } from 'remark';
12
13
  import { visit } from 'unist-util-visit';
13
14
  import { coreRemarkMdxPlugins, getAST } from '../../remark.js';
14
- import { isMdxJsxFlowElement } from '../../utils.js';
15
+ import { createUniqueVariableName, isMdxJsxFlowElement } from '../../utils.js';
15
16
  /**
16
17
  *
17
18
  * @param content The content to inject into
@@ -28,17 +29,73 @@ export const resolveComponentWithContent = (content, componentName, contentToInj
28
29
  return String(convertedContent);
29
30
  });
30
31
  /**
31
- * Everywhere where there is a component with the name `componentName`, replace it with the `treeToInject`
32
+ * Everywhere where there is a component with the name `componentName`, replace it with the `treeToInject`.
33
+ * New variables are also exported to be used for the variables. Additional mutations are made to support duplicated snippets
34
+ *
32
35
  * This function is used to resolve default imports
33
36
  * @param treeToInject
34
37
  * @param componentName
35
38
  * @returns
36
39
  */
37
40
  const remarkMdxResolveComponentWithContent = (treeToInject, componentName) => () => (tree) => {
41
+ let id = 0;
38
42
  visit(tree, isMdxJsxFlowElement, (node, i, parent) => {
43
+ var _a;
39
44
  if (node.name === componentName && parent && i != null) {
45
+ // Creating clone to restore treeToInject with default values at the end of operations
46
+ const treeToInjectClone = structuredClone(treeToInject);
40
47
  node.name = null;
41
- parent.children.splice(i, 1, ...treeToInject.children);
48
+ const { variableDeclarationNodes, snippetNodesToInject } = replaceVariablesWithProps(node, treeToInject, id);
49
+ parent.children.splice(i, 1, ...snippetNodesToInject);
50
+ tree.children.splice(((_a = tree.children[0]) === null || _a === void 0 ? void 0 : _a.type) === 'yaml' ? 1 : 0, 0, ...variableDeclarationNodes);
51
+ treeToInject = treeToInjectClone;
52
+ id += 1;
53
+ }
54
+ });
55
+ };
56
+ /**
57
+ * Replace the variables with value provided from the props by defining the variable before the snippet
58
+ * Also prevents duplicates by attaching a unique identifier to every variable (var to var_1)
59
+ *
60
+ * @param node
61
+ * @param treeToInject
62
+ * @param id a unique ID used to target the variable to prevent duplicated variable declarations
63
+ * @returns
64
+ */
65
+ const replaceVariablesWithProps = (node, treeToInject, id) => {
66
+ const variablesMap = {};
67
+ visit(treeToInject, (node) => {
68
+ var _a;
69
+ if ((node.type === 'mdxTextExpression' || node.type === 'mdxFlowExpression') &&
70
+ ((_a = node.data) === null || _a === void 0 ? void 0 : _a.estree)) {
71
+ node.data.estree = walk(node.data.estree, {
72
+ enter(jsNode) {
73
+ if (jsNode.type === 'Identifier') {
74
+ const uniqueName = createUniqueVariableName(jsNode.name, id);
75
+ // Replace node value with unique name
76
+ node.value = node.value.replace(jsNode.name, uniqueName);
77
+ variablesMap[uniqueName] = { type: 'unknown', value: 'undefined' };
78
+ jsNode.name = uniqueName;
79
+ }
80
+ },
81
+ });
42
82
  }
43
83
  });
84
+ node.attributes.forEach((attribute) => {
85
+ if (attribute.type === 'mdxJsxAttribute' && attribute.value) {
86
+ variablesMap[createUniqueVariableName(attribute.name, id)] =
87
+ typeof attribute.value === 'string'
88
+ ? { type: 'string', value: attribute.value }
89
+ : { type: 'unknown', value: attribute.value.value };
90
+ }
91
+ });
92
+ const variableDeclarationNodes = [];
93
+ Object.entries(variablesMap).map(([variable, value]) => {
94
+ const statement = `export const ${variable} = ${value.type === 'string' ? `"${value.value}"` : value.value}`;
95
+ variableDeclarationNodes.push(...getAST(statement).children);
96
+ });
97
+ return {
98
+ variableDeclarationNodes,
99
+ snippetNodesToInject: treeToInject.children,
100
+ };
44
101
  };
@@ -10,3 +10,4 @@ export declare const isImportDeclaration: (bodyChild: MdxNodeBodyChildType) => b
10
10
  export declare const isExport: (type: string) => boolean;
11
11
  export declare const isExportNode: (bodyChild: MdxNodeBodyChildType) => bodyChild is ExportNamedDeclaration | ExportDefaultDeclaration | ExportAllDeclaration;
12
12
  export declare const isMdxJsxFlowElement: (node: Node) => node is MdxJsxFlowElement;
13
+ export declare const createUniqueVariableName: (variableName: string, id: number) => string;
package/dist/mdx/utils.js CHANGED
@@ -14,3 +14,4 @@ export const isExport = (type) => [
14
14
  ].includes(type);
15
15
  export const isExportNode = (bodyChild) => isExport(bodyChild.type);
16
16
  export const isMdxJsxFlowElement = (node) => node.type === 'mdxJsxFlowElement';
17
+ export const createUniqueVariableName = (variableName, id) => `${variableName}_${id}`;