@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.
- package/dist/mdx/getMDXOptions.d.ts +3 -0
- package/dist/mdx/getMDXOptions.js +32 -0
- package/dist/mdx/index.d.ts +3 -0
- package/dist/mdx/index.js +3 -0
- package/dist/mdx/lib/findExportedNode.d.ts +2 -0
- package/dist/mdx/lib/findExportedNode.js +30 -0
- package/dist/mdx/lib/index.d.ts +3 -0
- package/dist/mdx/lib/index.js +3 -0
- package/dist/mdx/lib/mdx-utils.d.ts +8 -0
- package/dist/mdx/lib/mdx-utils.js +8 -0
- package/dist/mdx/lib/remark-utils.d.ts +13 -0
- package/dist/mdx/lib/remark-utils.js +136 -0
- package/dist/mdx/plugins/index.d.ts +2 -0
- package/dist/mdx/plugins/index.js +2 -0
- package/dist/mdx/plugins/rehype/index.d.ts +8 -0
- package/dist/mdx/plugins/rehype/index.js +8 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks.d.ts +4 -0
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +44 -0
- package/dist/mdx/plugins/rehype/rehypeLayouts.d.ts +1 -0
- package/dist/mdx/plugins/rehype/rehypeLayouts.js +133 -0
- package/dist/mdx/plugins/rehype/rehypeListRoles.d.ts +1 -0
- package/dist/mdx/plugins/rehype/rehypeListRoles.js +10 -0
- package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.d.ts +2 -0
- package/dist/mdx/plugins/rehype/rehypeMdxExtractExamples.js +64 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.d.ts +3 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/findParentSchema.js +9 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.d.ts +3 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/index.js +93 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.d.ts +17 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/insertSchema.js +83 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.d.ts +24 -0
- package/dist/mdx/plugins/rehype/rehypeMdxInjectEndpoint/parsers.js +251 -0
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.d.ts +15 -0
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/createCommentNode.js +20 -0
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.d.ts +5 -0
- package/dist/mdx/plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js +18 -0
- package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +1 -0
- package/dist/mdx/plugins/rehype/rehypeRawComponents.js +12 -0
- package/dist/mdx/plugins/rehype/rehypeZoomImages.d.ts +2 -0
- package/dist/mdx/plugins/rehype/rehypeZoomImages.js +15 -0
- package/dist/mdx/plugins/remark/index.d.ts +7 -0
- package/dist/mdx/plugins/remark/index.js +7 -0
- package/dist/mdx/plugins/remark/remarkFrames.d.ts +1 -0
- package/dist/mdx/plugins/remark/remarkFrames.js +37 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectRequire.d.ts +3 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectRequire.js +23 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.d.ts +3 -0
- package/dist/mdx/plugins/remark/remarkMdxInjectSnippets.js +26 -0
- package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkMdxRemoveJs/index.js +20 -0
- package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkMdxWrapDangerouslySetInnerHtml.js +28 -0
- package/dist/mdx/plugins/remark/remarkRemoveImports.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkRemoveImports.js +11 -0
- package/dist/mdx/plugins/remark/remarkTableOfContents.d.ts +1 -0
- package/dist/mdx/plugins/remark/remarkTableOfContents.js +57 -0
- package/dist/mdx/snippets/resolveImport/resolveComponentWithContent.js +60 -3
- package/dist/mdx/utils.d.ts +1 -0
- package/dist/mdx/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mdx/UserDefinedExampleData.d.ts +15 -0
- package/dist/types/mdx/UserDefinedExampleData.js +1 -0
- package/dist/types/mdx/index.d.ts +1 -0
- package/dist/types/mdx/index.js +1 -0
- package/package.json +24 -3
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { rehypeCodeBlocks, rehypeLayouts, rehypeListRoles, rehypeMdxExtractExamples, rehypeMdxInjectEndpoint, rehypeRawComponents, rehypeZoomImages, remarkFrames, remarkMdxInjectRequire, remarkMdxInjectSnippets, remarkMdxRemoveJs, remarkMdxWrapDangerouslySetInnerHtml, remarkRemoveImports, remarkTableOfContents, } from './plugins/index.js';
|
|
2
|
+
import rehypeMdxRemoveUnknownJsx from './plugins/rehype/rehypeMdxRemoveUnknownJsx/index.js';
|
|
3
|
+
export const getMDXOptions = ({ data }) => {
|
|
4
|
+
return {
|
|
5
|
+
remarkPlugins: [
|
|
6
|
+
[remarkMdxInjectRequire, data === null || data === void 0 ? void 0 : data.subdomain],
|
|
7
|
+
[remarkMdxInjectSnippets, data === null || data === void 0 ? void 0 : data.snippetTreeMap],
|
|
8
|
+
remarkMdxRemoveJs,
|
|
9
|
+
remarkFrames,
|
|
10
|
+
remarkTableOfContents,
|
|
11
|
+
remarkRemoveImports,
|
|
12
|
+
remarkMdxWrapDangerouslySetInnerHtml,
|
|
13
|
+
],
|
|
14
|
+
rehypePlugins: [
|
|
15
|
+
[
|
|
16
|
+
rehypeMdxRemoveUnknownJsx,
|
|
17
|
+
{
|
|
18
|
+
allowedComponents: data === null || data === void 0 ? void 0 : data.allowedComponents,
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
rehypeCodeBlocks,
|
|
22
|
+
rehypeListRoles,
|
|
23
|
+
rehypeMdxExtractExamples,
|
|
24
|
+
[rehypeMdxInjectEndpoint, data === null || data === void 0 ? void 0 : data.pageMetadata, data === null || data === void 0 ? void 0 : data.mintConfig],
|
|
25
|
+
rehypeRawComponents,
|
|
26
|
+
rehypeLayouts,
|
|
27
|
+
rehypeZoomImages,
|
|
28
|
+
],
|
|
29
|
+
format: 'mdx',
|
|
30
|
+
useDynamicImport: true,
|
|
31
|
+
};
|
|
32
|
+
};
|
package/dist/mdx/index.d.ts
CHANGED
package/dist/mdx/index.js
CHANGED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { nodeIncludesExport } from '../snippets/index.js';
|
|
3
|
+
import { isExportNode } from '../utils.js';
|
|
4
|
+
export const findExportedNodes = (tree, ...type) => {
|
|
5
|
+
const exports = [];
|
|
6
|
+
visit(tree, nodeIncludesExport, (node) => {
|
|
7
|
+
var _a;
|
|
8
|
+
const body = node.data.estree.body;
|
|
9
|
+
for (const bodyChild of body) {
|
|
10
|
+
if (isExportNode(bodyChild)) {
|
|
11
|
+
if (bodyChild.type === 'ExportAllDeclaration')
|
|
12
|
+
continue;
|
|
13
|
+
if (((_a = bodyChild.declaration) === null || _a === void 0 ? void 0 : _a.type) !== 'VariableDeclaration')
|
|
14
|
+
continue;
|
|
15
|
+
const declaration = bodyChild.declaration.declarations[0];
|
|
16
|
+
if (declaration == undefined)
|
|
17
|
+
continue;
|
|
18
|
+
const init = declaration.init;
|
|
19
|
+
if (init == null)
|
|
20
|
+
continue;
|
|
21
|
+
if (!type.includes(init.type))
|
|
22
|
+
continue;
|
|
23
|
+
if (declaration.id.type !== 'Identifier')
|
|
24
|
+
continue;
|
|
25
|
+
exports.push(declaration.id.name);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
return exports;
|
|
30
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
|
|
2
|
+
import { Node } from 'unist';
|
|
3
|
+
export declare const isMdxJsxFlowElementHast: (node: Node) => node is MdxJsxFlowElementHast;
|
|
4
|
+
export declare const isMdxJsxAttribute: (attribute: MdxJsxAttribute | MdxJsxExpressionAttribute) => attribute is MdxJsxAttribute;
|
|
5
|
+
export declare const paramFieldLocations: readonly ["body", "query", "auth", "cookie", "path", "header"];
|
|
6
|
+
export type ParamFieldLocation = (typeof paramFieldLocations)[number];
|
|
7
|
+
export type FieldLocation = ParamFieldLocation | 'response';
|
|
8
|
+
export declare const isParamFieldLocation: (str: string | undefined) => str is "query" | "header" | "cookie" | "path" | "body" | "auth";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export const isMdxJsxFlowElementHast = (node) => {
|
|
2
|
+
return node.type === 'mdxJsxFlowElement';
|
|
3
|
+
};
|
|
4
|
+
export const isMdxJsxAttribute = (attribute) => attribute.type === 'mdxJsxAttribute';
|
|
5
|
+
export const paramFieldLocations = ['body', 'query', 'auth', 'cookie', 'path', 'header'];
|
|
6
|
+
export const isParamFieldLocation = (str) => {
|
|
7
|
+
return paramFieldLocations.includes(str);
|
|
8
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export function addImportString(tree: any, jsx: any): void;
|
|
2
|
+
export function addImport(tree: any, mod: any, name: any): string;
|
|
3
|
+
export function addDefaultImport(tree: any, mod: any, name: any): string;
|
|
4
|
+
export function addExport(tree: any, name: any, value: any): void;
|
|
5
|
+
export function normalizeTokens(tokens: any): any[][];
|
|
6
|
+
export function simplifyToken(token: any): string | any[];
|
|
7
|
+
export function createMdxJsxAttribute(key: any, value: any): {
|
|
8
|
+
type: string;
|
|
9
|
+
name: any;
|
|
10
|
+
value: any;
|
|
11
|
+
};
|
|
12
|
+
export function toMdxJsxFlowElement(input: any): import("mdast").Content | undefined;
|
|
13
|
+
export function getEsmNode(input: any): import("mdast").Content | undefined;
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
import * as acorn from 'acorn';
|
|
2
|
+
import { fromMarkdown } from 'mdast-util-from-markdown';
|
|
3
|
+
import { mdxJsxFromMarkdown } from 'mdast-util-mdx-jsx';
|
|
4
|
+
import { mdxjsEsmFromMarkdown } from 'mdast-util-mdxjs-esm';
|
|
5
|
+
import { mdxJsx } from 'micromark-extension-mdx-jsx';
|
|
6
|
+
import { mdxjsEsm } from 'micromark-extension-mdxjs-esm';
|
|
7
|
+
export const createMdxJsxAttribute = (key, value) => {
|
|
8
|
+
return {
|
|
9
|
+
type: 'mdxJsxAttribute',
|
|
10
|
+
name: key,
|
|
11
|
+
value,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export const toMdxJsxFlowElement = (input) => {
|
|
15
|
+
const tree = fromMarkdown(input, {
|
|
16
|
+
extensions: [mdxJsx({ acorn: acorn, addResult: true })],
|
|
17
|
+
mdastExtensions: [mdxJsxFromMarkdown()],
|
|
18
|
+
});
|
|
19
|
+
return tree.children[0];
|
|
20
|
+
};
|
|
21
|
+
export const getEsmNode = (input) => {
|
|
22
|
+
const tree = fromMarkdown(input, {
|
|
23
|
+
extensions: [mdxjsEsm({ acorn, addResult: true })],
|
|
24
|
+
mdastExtensions: [mdxjsEsmFromMarkdown],
|
|
25
|
+
});
|
|
26
|
+
return tree.children[0];
|
|
27
|
+
};
|
|
28
|
+
export function addImportString(tree, jsx) {
|
|
29
|
+
tree.children.unshift(getEsmNode(jsx));
|
|
30
|
+
}
|
|
31
|
+
export function addImport(tree, mod, name) {
|
|
32
|
+
const jsx = `import { ${name} as _${name} } from '${mod}'`;
|
|
33
|
+
tree.children.unshift(getEsmNode(jsx));
|
|
34
|
+
return `_${name}`;
|
|
35
|
+
}
|
|
36
|
+
export function addDefaultImport(tree, mod, name) {
|
|
37
|
+
const jsx = `import _${name} from '${mod}'`;
|
|
38
|
+
tree.children.unshift(getEsmNode(jsx));
|
|
39
|
+
return `_${name}`;
|
|
40
|
+
}
|
|
41
|
+
export function addExport(tree, name, value) {
|
|
42
|
+
const jsx = `export const ${name} = ${JSON.stringify(value)}`;
|
|
43
|
+
tree.children.push(getEsmNode(jsx));
|
|
44
|
+
}
|
|
45
|
+
const newlineRe = /\r\n|\r|\n/;
|
|
46
|
+
// Empty lines need to contain a single empty token, denoted with { empty: true }
|
|
47
|
+
function normalizeEmptyLines(line) {
|
|
48
|
+
if (line.length === 0) {
|
|
49
|
+
line.push({
|
|
50
|
+
types: ['plain'],
|
|
51
|
+
content: '',
|
|
52
|
+
empty: true,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
else if (line.length === 1 && line[0].content === '') {
|
|
56
|
+
line[0].empty = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function appendTypes(types, add) {
|
|
60
|
+
const typesSize = types.length;
|
|
61
|
+
if (typesSize > 0 && types[typesSize - 1] === add) {
|
|
62
|
+
return types;
|
|
63
|
+
}
|
|
64
|
+
return types.concat(add);
|
|
65
|
+
}
|
|
66
|
+
// Takes an array of Prism's tokens and groups them by line, turning plain
|
|
67
|
+
// strings into tokens as well. Tokens can become recursive in some cases,
|
|
68
|
+
// which means that their types are concatenated. Plain-string tokens however
|
|
69
|
+
// are always of type "plain".
|
|
70
|
+
// This is not recursive to avoid exceeding the call-stack limit, since it's unclear
|
|
71
|
+
// how nested Prism's tokens can become
|
|
72
|
+
export function normalizeTokens(tokens) {
|
|
73
|
+
const typeArrStack = [[]];
|
|
74
|
+
const tokenArrStack = [tokens];
|
|
75
|
+
const tokenArrIndexStack = [0];
|
|
76
|
+
const tokenArrSizeStack = [tokens.length];
|
|
77
|
+
let i = 0;
|
|
78
|
+
let stackIndex = 0;
|
|
79
|
+
let currentLine = [];
|
|
80
|
+
const acc = [currentLine];
|
|
81
|
+
while (stackIndex > -1) {
|
|
82
|
+
while ((i = tokenArrIndexStack[stackIndex]++) < tokenArrSizeStack[stackIndex]) {
|
|
83
|
+
let content;
|
|
84
|
+
let types = typeArrStack[stackIndex];
|
|
85
|
+
const tokenArr = tokenArrStack[stackIndex];
|
|
86
|
+
const token = tokenArr[i];
|
|
87
|
+
// Determine content and append type to types if necessary
|
|
88
|
+
if (typeof token === 'string') {
|
|
89
|
+
types = stackIndex > 0 ? types : ['plain'];
|
|
90
|
+
content = token;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
types = appendTypes(types, token.type);
|
|
94
|
+
if (token.alias) {
|
|
95
|
+
types = appendTypes(types, token.alias);
|
|
96
|
+
}
|
|
97
|
+
content = token.content;
|
|
98
|
+
}
|
|
99
|
+
// If token.content is an array, increase the stack depth and repeat this while-loop
|
|
100
|
+
if (typeof content !== 'string') {
|
|
101
|
+
stackIndex++;
|
|
102
|
+
typeArrStack.push(types);
|
|
103
|
+
tokenArrStack.push(content);
|
|
104
|
+
tokenArrIndexStack.push(0);
|
|
105
|
+
tokenArrSizeStack.push(content.length);
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
// Split by newlines
|
|
109
|
+
const splitByNewlines = content.split(newlineRe);
|
|
110
|
+
const newlineCount = splitByNewlines.length;
|
|
111
|
+
currentLine.push({ types, content: splitByNewlines[0] });
|
|
112
|
+
// Create a new line for each string on a new line
|
|
113
|
+
for (let i = 1; i < newlineCount; i++) {
|
|
114
|
+
normalizeEmptyLines(currentLine);
|
|
115
|
+
acc.push((currentLine = []));
|
|
116
|
+
currentLine.push({ types, content: splitByNewlines[i] });
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// Decreate the stack depth
|
|
120
|
+
stackIndex--;
|
|
121
|
+
typeArrStack.pop();
|
|
122
|
+
tokenArrStack.pop();
|
|
123
|
+
tokenArrIndexStack.pop();
|
|
124
|
+
tokenArrSizeStack.pop();
|
|
125
|
+
}
|
|
126
|
+
normalizeEmptyLines(currentLine);
|
|
127
|
+
return acc;
|
|
128
|
+
}
|
|
129
|
+
export function simplifyToken(token) {
|
|
130
|
+
if (typeof token === 'string')
|
|
131
|
+
return token;
|
|
132
|
+
return [
|
|
133
|
+
token.type,
|
|
134
|
+
Array.isArray(token.content) ? token.content.map(simplifyToken) : token.content,
|
|
135
|
+
];
|
|
136
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './rehypeMdxInjectEndpoint/index.js';
|
|
2
|
+
export * from './rehypeMdxRemoveUnknownJsx/index.js';
|
|
3
|
+
export * from './rehypeMdxExtractExamples.js';
|
|
4
|
+
export * from './rehypeCodeBlocks.js';
|
|
5
|
+
export * from './rehypeLayouts.js';
|
|
6
|
+
export * from './rehypeListRoles.js';
|
|
7
|
+
export * from './rehypeRawComponents.js';
|
|
8
|
+
export * from './rehypeZoomImages.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from './rehypeMdxInjectEndpoint/index.js';
|
|
2
|
+
export * from './rehypeMdxRemoveUnknownJsx/index.js';
|
|
3
|
+
export * from './rehypeMdxExtractExamples.js';
|
|
4
|
+
export * from './rehypeCodeBlocks.js';
|
|
5
|
+
export * from './rehypeLayouts.js';
|
|
6
|
+
export * from './rehypeListRoles.js';
|
|
7
|
+
export * from './rehypeRawComponents.js';
|
|
8
|
+
export * from './rehypeZoomImages.js';
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
const exampleNames = ['RequestExample', 'ResponseExample'];
|
|
3
|
+
const flowElementType = 'mdxJsxFlowElement';
|
|
4
|
+
function isElement(node, key = 'type', element = 'element') {
|
|
5
|
+
return node != undefined && node[key] === element;
|
|
6
|
+
}
|
|
7
|
+
function addCodeBlocks(tree) {
|
|
8
|
+
const preTree = { children: [] };
|
|
9
|
+
visit(tree, (node, i, parent) => {
|
|
10
|
+
var _a, _b;
|
|
11
|
+
if (parent == null || i == null || !isElement(node) || !isElement(node, 'tagName', 'pre')) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
const code = node.children[0];
|
|
15
|
+
if (!isElement(code, 'tagName', 'code'))
|
|
16
|
+
return;
|
|
17
|
+
let filename = undefined;
|
|
18
|
+
const isFlowElement = isElement(parent, 'type', flowElementType);
|
|
19
|
+
const parentName = isFlowElement ? parent.name : undefined;
|
|
20
|
+
if (parentName && exampleNames.includes(parentName)) {
|
|
21
|
+
const parentType = parentName.slice(0, -7);
|
|
22
|
+
filename = i === 0 ? parentType : `${parentType} ${i + 1}`;
|
|
23
|
+
if (!((_a = code.data) === null || _a === void 0 ? void 0 : _a.meta)) {
|
|
24
|
+
code.data = Object.assign(Object.assign({}, code.data), { meta: filename });
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (((_b = code.data) === null || _b === void 0 ? void 0 : _b.meta) && typeof code.data.meta === 'string') {
|
|
28
|
+
filename = code.data.meta;
|
|
29
|
+
}
|
|
30
|
+
const wrap = {
|
|
31
|
+
type: flowElementType,
|
|
32
|
+
name: 'CodeBlock',
|
|
33
|
+
attributes: [{ type: 'mdxJsxAttribute', name: 'filename', value: filename !== null && filename !== void 0 ? filename : '' }],
|
|
34
|
+
data: { _mdxExplicitJsx: true },
|
|
35
|
+
children: [],
|
|
36
|
+
};
|
|
37
|
+
wrap.children = [node];
|
|
38
|
+
parent.children[i] = wrap;
|
|
39
|
+
});
|
|
40
|
+
tree.children = [...preTree.children, ...tree.children];
|
|
41
|
+
}
|
|
42
|
+
export function rehypeCodeBlocks() {
|
|
43
|
+
return addCodeBlocks;
|
|
44
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function rehypeLayouts(): (tree: any) => void;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
export const rehypeLayouts = () => {
|
|
2
|
+
return (tree) => {
|
|
3
|
+
tree.children.push({
|
|
4
|
+
type: 'mdxjsEsm',
|
|
5
|
+
value: `export default (props) => <MDXContentController {...props} tableOfContents={tableOfContents} userDefinedExamples={userDefinedExamples} endpoint={endpoint} pageMetadata={pageMetadata}>{props.children}</MDXContentController>`,
|
|
6
|
+
data: {
|
|
7
|
+
estree: {
|
|
8
|
+
type: 'Program',
|
|
9
|
+
sourceType: 'module',
|
|
10
|
+
body: [
|
|
11
|
+
{
|
|
12
|
+
type: 'ExportDefaultDeclaration',
|
|
13
|
+
declaration: {
|
|
14
|
+
type: 'ArrowFunctionExpression',
|
|
15
|
+
async: false,
|
|
16
|
+
expression: true,
|
|
17
|
+
generator: false,
|
|
18
|
+
id: null,
|
|
19
|
+
body: {
|
|
20
|
+
type: 'JSXElement',
|
|
21
|
+
children: [
|
|
22
|
+
{
|
|
23
|
+
type: 'JSXExpressionContainer',
|
|
24
|
+
expression: {
|
|
25
|
+
type: 'MemberExpression',
|
|
26
|
+
computed: false,
|
|
27
|
+
optional: false,
|
|
28
|
+
object: {
|
|
29
|
+
name: 'props',
|
|
30
|
+
type: 'Identifier',
|
|
31
|
+
},
|
|
32
|
+
property: {
|
|
33
|
+
name: 'children',
|
|
34
|
+
type: 'Identifier',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
closingElement: {
|
|
40
|
+
type: 'JSXClosingElement',
|
|
41
|
+
name: {
|
|
42
|
+
type: 'JSXIdentifier',
|
|
43
|
+
name: 'MDXContentController',
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
openingElement: {
|
|
47
|
+
type: 'JSXOpeningElement',
|
|
48
|
+
selfClosing: false,
|
|
49
|
+
name: {
|
|
50
|
+
type: 'JSXIdentifier',
|
|
51
|
+
name: 'MDXContentController',
|
|
52
|
+
},
|
|
53
|
+
attributes: [
|
|
54
|
+
{
|
|
55
|
+
type: 'JSXSpreadAttribute',
|
|
56
|
+
argument: {
|
|
57
|
+
type: 'Identifier',
|
|
58
|
+
name: 'props',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
type: 'JSXAttribute',
|
|
63
|
+
name: {
|
|
64
|
+
type: 'JSXIdentifier',
|
|
65
|
+
name: 'tableOfContents',
|
|
66
|
+
},
|
|
67
|
+
value: {
|
|
68
|
+
type: 'JSXExpressionContainer',
|
|
69
|
+
expression: {
|
|
70
|
+
type: 'Identifier',
|
|
71
|
+
name: 'tableOfContents',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
type: 'JSXAttribute',
|
|
77
|
+
name: {
|
|
78
|
+
type: 'JSXIdentifier',
|
|
79
|
+
name: 'userDefinedExamples',
|
|
80
|
+
},
|
|
81
|
+
value: {
|
|
82
|
+
type: 'JSXExpressionContainer',
|
|
83
|
+
expression: {
|
|
84
|
+
type: 'Identifier',
|
|
85
|
+
name: 'userDefinedExamples',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: 'JSXAttribute',
|
|
91
|
+
name: {
|
|
92
|
+
type: 'JSXIdentifier',
|
|
93
|
+
name: 'endpoint',
|
|
94
|
+
},
|
|
95
|
+
value: {
|
|
96
|
+
type: 'JSXExpressionContainer',
|
|
97
|
+
expression: {
|
|
98
|
+
type: 'Identifier',
|
|
99
|
+
name: 'endpoint',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
type: 'JSXAttribute',
|
|
105
|
+
name: {
|
|
106
|
+
type: 'JSXIdentifier',
|
|
107
|
+
name: 'pageMetadata',
|
|
108
|
+
},
|
|
109
|
+
value: {
|
|
110
|
+
type: 'JSXExpressionContainer',
|
|
111
|
+
expression: {
|
|
112
|
+
type: 'Identifier',
|
|
113
|
+
name: 'pageMetadata',
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
],
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
params: [
|
|
121
|
+
{
|
|
122
|
+
type: 'Identifier',
|
|
123
|
+
name: 'props',
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
});
|
|
132
|
+
};
|
|
133
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export function rehypeListRoles(): (tree: any) => void;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { toHtml } from 'hast-util-to-html';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { addExport, isMdxJsxFlowElementHast } from '../../lib/index.js';
|
|
4
|
+
const langFilename = (className) => {
|
|
5
|
+
switch (className) {
|
|
6
|
+
case 'language-shell':
|
|
7
|
+
return 'Bash';
|
|
8
|
+
case 'language-json':
|
|
9
|
+
return 'JSON';
|
|
10
|
+
case 'language-js':
|
|
11
|
+
return 'JavaScript';
|
|
12
|
+
default:
|
|
13
|
+
const language = className.substring(9);
|
|
14
|
+
return language.charAt(0).toUpperCase() + language.slice(1);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
export const rehypeMdxExtractExamples = () => {
|
|
18
|
+
return (tree) => {
|
|
19
|
+
let request;
|
|
20
|
+
let response;
|
|
21
|
+
visit(tree, isMdxJsxFlowElementHast, (node, i, parent) => {
|
|
22
|
+
if (node.name === 'RequestExample') {
|
|
23
|
+
request = request !== null && request !== void 0 ? request : {
|
|
24
|
+
type: node.name,
|
|
25
|
+
children: parseChildren(node),
|
|
26
|
+
};
|
|
27
|
+
if (parent && i !== null)
|
|
28
|
+
parent.children.splice(i, 1);
|
|
29
|
+
}
|
|
30
|
+
else if (node.name === 'ResponseExample') {
|
|
31
|
+
response = response !== null && response !== void 0 ? response : {
|
|
32
|
+
type: node.name,
|
|
33
|
+
children: parseChildren(node),
|
|
34
|
+
};
|
|
35
|
+
if (parent && i !== null)
|
|
36
|
+
parent.children.splice(i, 1);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
addExport(tree, 'userDefinedExamples', { request, response });
|
|
40
|
+
return tree;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
const parseChildren = (node) => {
|
|
44
|
+
return node.children.filter(isMdxJsxFlowElementHast).flatMap((child) => {
|
|
45
|
+
var _a, _b, _c;
|
|
46
|
+
const preComponent = child.children[0];
|
|
47
|
+
if ((preComponent === null || preComponent === void 0 ? void 0 : preComponent.type) !== 'element')
|
|
48
|
+
return [];
|
|
49
|
+
const html = toHtml(preComponent);
|
|
50
|
+
let filename = Array.isArray((_a = preComponent.properties) === null || _a === void 0 ? void 0 : _a.className) &&
|
|
51
|
+
typeof ((_b = preComponent.properties) === null || _b === void 0 ? void 0 : _b.className[0]) === 'string'
|
|
52
|
+
? langFilename(preComponent.properties.className[0])
|
|
53
|
+
: '';
|
|
54
|
+
if ('attributes' in child && typeof ((_c = child.attributes[0]) === null || _c === void 0 ? void 0 : _c.value) === 'string') {
|
|
55
|
+
filename = child.attributes[0].value;
|
|
56
|
+
}
|
|
57
|
+
return [
|
|
58
|
+
{
|
|
59
|
+
filename,
|
|
60
|
+
html,
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
});
|
|
64
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export const findParentSchema = (tagName, parents, nodeToSchema) => {
|
|
2
|
+
// find the nearest parent node that has an associated DataSchema
|
|
3
|
+
const parentField = parents.findLast((node) => nodeToSchema.has(node));
|
|
4
|
+
// we only want parents that have the same tag name (e.g. ParamField)
|
|
5
|
+
if (parentField === undefined || parentField.name !== tagName) {
|
|
6
|
+
return undefined;
|
|
7
|
+
}
|
|
8
|
+
return nodeToSchema.get(parentField);
|
|
9
|
+
};
|