@mintlify/common 1.0.397 → 1.0.399
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/lib/remark-utils.d.ts +8 -8
- package/dist/mdx/lib/remark-utils.js +23 -25
- package/dist/mdx/plugins/rehype/rehypeCodeBlocks.js +9 -2
- package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/parsers.d.ts +1 -1
- package/dist/mdx/plugins/rehype/rehypeMdxExtractEndpoint/parsers.js +10 -4
- package/dist/mdx/plugins/rehype/rehypeRawComponents.d.ts +2 -1
- package/dist/mdx/plugins/rehype/rehypeRawComponents.js +6 -3
- package/dist/mdx/plugins/rehype/rehypeUnicodeIds.d.ts +2 -1
- package/dist/mdx/plugins/rehype/rehypeUnicodeIds.js +9 -7
- package/dist/mdx/plugins/remark/remarkExtractChangelogFilters.d.ts +3 -1
- package/dist/mdx/plugins/remark/remarkExtractChangelogFilters.js +29 -32
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.d.ts +3 -1
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +71 -55
- package/dist/mdx/plugins/remark/remarkFrames.d.ts +2 -1
- package/dist/mdx/plugins/remark/remarkFrames.js +0 -27
- package/dist/mdx/plugins/remark/remarkHeadingIds.d.ts +2 -1
- package/dist/mdx/plugins/remark/remarkHeadingIds.js +4 -3
- package/dist/mdx/snippets/resolveImport/index.js +5 -1
- package/dist/openapi/parseOpenApiString.js +4 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export function
|
|
7
|
-
export
|
|
8
|
-
export
|
|
1
|
+
import type { RootContent as HastRootContent } from 'hast';
|
|
2
|
+
import type { RootContent as MdastRootContent } from 'mdast';
|
|
3
|
+
import type { MdxJsxAttribute, MdxJsxAttributeValueExpression } from 'mdast-util-mdx-jsx';
|
|
4
|
+
type RootContent = MdastRootContent | HastRootContent;
|
|
5
|
+
export declare const createMdxJsxAttribute: (key: string, value: MdxJsxAttributeValueExpression | string | null | undefined | number | boolean) => MdxJsxAttribute;
|
|
6
|
+
export declare function getUnicodeId(title: string): string;
|
|
7
|
+
export declare const getTableOfContentsTitle: (node: RootContent, index?: number, children?: RootContent[]) => string;
|
|
8
|
+
export {};
|
|
@@ -1,39 +1,37 @@
|
|
|
1
|
-
import * as acorn from 'acorn';
|
|
2
|
-
import { fromMarkdown } from 'mdast-util-from-markdown';
|
|
3
|
-
import { mdxJsxFromMarkdown } from 'mdast-util-mdx-jsx';
|
|
4
|
-
import { mdxJsx } from 'micromark-extension-mdx-jsx';
|
|
5
1
|
export const createMdxJsxAttribute = (key, value) => {
|
|
6
2
|
return {
|
|
7
3
|
type: 'mdxJsxAttribute',
|
|
8
4
|
name: key,
|
|
9
|
-
|
|
5
|
+
// we want to cast here to avoid the type checker failing on number/boolean values
|
|
6
|
+
// which will get serialized properly, but just aren't added to the type
|
|
7
|
+
value: value,
|
|
10
8
|
};
|
|
11
9
|
};
|
|
12
|
-
export
|
|
13
|
-
const tree = fromMarkdown(input, {
|
|
14
|
-
extensions: [mdxJsx({ acorn: acorn, addResult: true })],
|
|
15
|
-
mdastExtensions: [mdxJsxFromMarkdown()],
|
|
16
|
-
});
|
|
17
|
-
return tree.children[0];
|
|
18
|
-
};
|
|
19
|
-
export const getUnicodeId = (title) => {
|
|
10
|
+
export function getUnicodeId(title) {
|
|
20
11
|
return encodeURIComponent(title.toLowerCase().trim().replace(/\s+/g, '-'));
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
}
|
|
13
|
+
const EMPTY_CHILDREN = [];
|
|
14
|
+
export const getTableOfContentsTitle = (node, index = 1, children = EMPTY_CHILDREN) => {
|
|
15
|
+
var _a;
|
|
16
|
+
if ('name' in node && node.name === 'Update') {
|
|
17
|
+
const labelAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'label' && typeof attr.value === 'string');
|
|
18
|
+
return (_a = labelAttr === null || labelAttr === void 0 ? void 0 : labelAttr.value) !== null && _a !== void 0 ? _a : '';
|
|
27
19
|
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
20
|
+
const lastChild = children[index - 1];
|
|
21
|
+
const isText = node.type === 'text';
|
|
22
|
+
const isInlineCode = node.type === 'inlineCode';
|
|
23
|
+
const isLastChildMdx = (lastChild === null || lastChild === void 0 ? void 0 : lastChild.type) !== 'mdxJsxFlowElement';
|
|
24
|
+
const isLastChildSmall = lastChild &&
|
|
25
|
+
'value' in lastChild &&
|
|
26
|
+
typeof lastChild.value === 'string' &&
|
|
27
|
+
!lastChild.value.startsWith('<small');
|
|
28
|
+
if (isInlineCode || (isText && (isLastChildMdx || isLastChildSmall))) {
|
|
31
29
|
return node.value;
|
|
32
30
|
}
|
|
33
|
-
if (node.children) {
|
|
31
|
+
if ('children' in node && Array.isArray(node.children)) {
|
|
34
32
|
let title = '';
|
|
35
|
-
node.children.forEach((
|
|
36
|
-
title +=
|
|
33
|
+
node.children.forEach((subNode, index, children) => {
|
|
34
|
+
title += getTableOfContentsTitle(subNode, index, children);
|
|
37
35
|
});
|
|
38
36
|
return title;
|
|
39
37
|
}
|
|
@@ -5,7 +5,6 @@ function isElement(node, key = 'type', element = 'element') {
|
|
|
5
5
|
return node != undefined && node[key] === element;
|
|
6
6
|
}
|
|
7
7
|
function addCodeBlocks(tree) {
|
|
8
|
-
const preTree = { children: [] };
|
|
9
8
|
visit(tree, (node, i, parent) => {
|
|
10
9
|
var _a, _b;
|
|
11
10
|
if (parent == null || i == null || !isElement(node) || !isElement(node, 'tagName', 'pre')) {
|
|
@@ -18,6 +17,7 @@ function addCodeBlocks(tree) {
|
|
|
18
17
|
let isExpandable = false;
|
|
19
18
|
const isFlowElement = isElement(parent, 'type', flowElementType);
|
|
20
19
|
const parentName = isFlowElement ? parent.name : undefined;
|
|
20
|
+
const properties = code.type === 'element' ? Object.entries(code.properties) : [];
|
|
21
21
|
if (parentName && exampleNames.includes(parentName)) {
|
|
22
22
|
const parentType = parentName.slice(0, -7);
|
|
23
23
|
filename = i === 0 ? parentType : `${parentType} ${i + 1}`;
|
|
@@ -38,6 +38,13 @@ function addCodeBlocks(tree) {
|
|
|
38
38
|
attributes: [
|
|
39
39
|
{ type: 'mdxJsxAttribute', name: 'filename', value: filename !== null && filename !== void 0 ? filename : '' },
|
|
40
40
|
{ type: 'mdxJsxAttribute', name: 'expandable', value: isExpandable.toString() },
|
|
41
|
+
...properties
|
|
42
|
+
.filter(([_key, val]) => val != null)
|
|
43
|
+
.map(([key, val]) => ({
|
|
44
|
+
type: 'mdxJsxAttribute',
|
|
45
|
+
name: key,
|
|
46
|
+
value: Array.isArray(val) ? val.join(' ') : val === null || val === void 0 ? void 0 : val.toString(),
|
|
47
|
+
})),
|
|
41
48
|
],
|
|
42
49
|
data: { _mdxExplicitJsx: true },
|
|
43
50
|
children: [],
|
|
@@ -45,7 +52,7 @@ function addCodeBlocks(tree) {
|
|
|
45
52
|
wrap.children = [node];
|
|
46
53
|
parent.children[i] = wrap;
|
|
47
54
|
});
|
|
48
|
-
tree.children = [...
|
|
55
|
+
tree.children = [...tree.children];
|
|
49
56
|
}
|
|
50
57
|
export function rehypeCodeBlocks() {
|
|
51
58
|
return addCodeBlocks;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MintConfig } from '@mintlify/models';
|
|
2
2
|
import { DataSchema, DocsConfig, HttpMethod, SecurityOption, Server } from '@mintlify/validation';
|
|
3
|
-
import { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
|
|
3
|
+
import type { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
|
|
4
4
|
import type { FieldLocation } from '../../../lib/mdx-utils.js';
|
|
5
5
|
export declare const parseApiString: (apiString: string, config?: MintConfig | DocsConfig) => {
|
|
6
6
|
servers?: Server[];
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
1
2
|
import { getSecurityOptionsForAuthMethod } from '../../../../index.js';
|
|
2
3
|
import { isAbsoluteUrl } from '../../../../isAbsoluteUrl.js';
|
|
3
4
|
import { isDocsConfig } from '../../../../isDocsConfig.js';
|
|
4
5
|
import { isMdxJsxAttribute, isParamFieldLocation } from '../../../lib/mdx-utils.js';
|
|
6
|
+
const VALID_METHODS = Object.values(OpenAPIV3.HttpMethods);
|
|
5
7
|
export const parseApiString = (apiString, config) => {
|
|
6
8
|
const components = apiString.trim().split(/\s+/);
|
|
7
9
|
if (!components[0] || !components[1] || components.length > 2) {
|
|
8
10
|
throw new Error('improperly formatted api string');
|
|
9
11
|
}
|
|
10
|
-
const
|
|
12
|
+
const upperMethod = components[0];
|
|
13
|
+
const endpointStr = components[1];
|
|
11
14
|
const method = upperMethod.toLowerCase();
|
|
12
|
-
if (!
|
|
15
|
+
if (!VALID_METHODS.includes(method)) {
|
|
13
16
|
throw new Error('invalid http method');
|
|
14
17
|
}
|
|
15
18
|
const { origin, path } = parseEndpoint(endpointStr);
|
|
@@ -204,7 +207,9 @@ export const parseTypeString = (typeString) => {
|
|
|
204
207
|
const lowerTypeString = typeString.toLowerCase();
|
|
205
208
|
const simpleSchemaType = typeStringToSchemaType[lowerTypeString];
|
|
206
209
|
if (lowerTypeString.includes('|')) {
|
|
207
|
-
const
|
|
210
|
+
const splitLowerTypeString = lowerTypeString.split('|');
|
|
211
|
+
const left = splitLowerTypeString[0];
|
|
212
|
+
const right = splitLowerTypeString[1];
|
|
208
213
|
if (left && right) {
|
|
209
214
|
const leftSchema = parseTypeString(left.trim());
|
|
210
215
|
const rightSchema = parseTypeString(right.trim());
|
|
@@ -238,7 +243,8 @@ export const parseTypeString = (typeString) => {
|
|
|
238
243
|
const regexMatch = genericStringRegex.exec(lowerTypeString);
|
|
239
244
|
if (regexMatch !== null) {
|
|
240
245
|
// unpack capture group 1 (foo) and 2 (bar)
|
|
241
|
-
const
|
|
246
|
+
const superType = regexMatch[1];
|
|
247
|
+
const subType = regexMatch[2];
|
|
242
248
|
if (superType && subType && typeStringToSchemaType[superType] === 'array') {
|
|
243
249
|
// catches type strings like array<bar>
|
|
244
250
|
// recursively determine the type of everything within the angle brackets
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Pluggable } from 'unified';
|
|
2
|
+
export declare const rehypeRawComponents: Pluggable;
|
|
@@ -2,10 +2,13 @@ import { fromHtml } from 'hast-util-from-html';
|
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
export const rehypeRawComponents = () => {
|
|
4
4
|
return (tree) => {
|
|
5
|
-
visit(tree, 'raw', (raw,
|
|
5
|
+
visit(tree, 'raw', (raw, index, parent) => {
|
|
6
6
|
const rawAst = fromHtml(raw.value, { fragment: true });
|
|
7
|
-
if (parent &&
|
|
8
|
-
parent.children
|
|
7
|
+
if (parent && index !== undefined) {
|
|
8
|
+
// @ts-expect-error we're passing a component of type Root to parent.children which
|
|
9
|
+
// is fine even though parent.children should only take RootContent, bc `remark`
|
|
10
|
+
// will flatten out Roots into single nodes of type RootContent when serializing
|
|
11
|
+
parent.children[index] = rawAst;
|
|
9
12
|
}
|
|
10
13
|
});
|
|
11
14
|
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Pluggable } from 'unified';
|
|
2
|
+
export declare const rehypeUnicodeIds: Pluggable;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
-
import { getUnicodeId,
|
|
2
|
+
import { getUnicodeId, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
3
3
|
const DEEPLINKABLE_COMPONENTS = ['Heading', 'Update', 'Accordion'];
|
|
4
|
-
export
|
|
4
|
+
export const rehypeUnicodeIds = () => {
|
|
5
5
|
return (tree) => {
|
|
6
6
|
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
7
|
-
if (node
|
|
8
|
-
const title =
|
|
7
|
+
if (node.name && DEEPLINKABLE_COMPONENTS.includes(node.name)) {
|
|
8
|
+
const title = getTableOfContentsTitle(node);
|
|
9
9
|
const encodedId = getUnicodeId(title);
|
|
10
|
-
const existingIdIndex = node.attributes.findIndex((attr) => attr.name === 'id');
|
|
11
|
-
if (existingIdIndex !== -1 &&
|
|
10
|
+
const existingIdIndex = node.attributes.findIndex((attr) => 'name' in attr && attr.name === 'id');
|
|
11
|
+
if (existingIdIndex !== -1 &&
|
|
12
|
+
node.attributes[existingIdIndex] &&
|
|
13
|
+
!node.attributes[existingIdIndex].value) {
|
|
12
14
|
node.attributes[existingIdIndex].value = encodedId;
|
|
13
15
|
}
|
|
14
16
|
}
|
|
15
17
|
});
|
|
16
18
|
};
|
|
17
|
-
}
|
|
19
|
+
};
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { MdxExtracts } from '../../../types/index.js';
|
|
3
|
+
export declare function remarkExtractChangelogFilters(mdxExtracts?: MdxExtracts): (tree: Root) => void;
|
|
@@ -1,43 +1,40 @@
|
|
|
1
1
|
export function remarkExtractChangelogFilters(mdxExtracts) {
|
|
2
2
|
return (tree) => {
|
|
3
|
+
var _a, _b;
|
|
3
4
|
const tagCounts = new Map();
|
|
4
5
|
for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
|
|
5
6
|
const node = tree.children[nodeIndex];
|
|
6
|
-
if (node.type
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return null;
|
|
27
|
-
})
|
|
28
|
-
.filter(Boolean);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (Array.isArray(tags)) {
|
|
33
|
-
tags.forEach((tag) => {
|
|
34
|
-
if (!!tag.trim()) {
|
|
35
|
-
tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
|
|
36
|
-
}
|
|
37
|
-
});
|
|
7
|
+
if (!node || node.type !== 'mdxJsxFlowElement' || node.name !== 'Update') {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
const tagsAttribute = node.attributes.find((attr) => 'name' in attr && attr.name === 'tags');
|
|
11
|
+
if (!tagsAttribute || !tagsAttribute.value || typeof tagsAttribute.value !== 'object') {
|
|
12
|
+
continue;
|
|
13
|
+
}
|
|
14
|
+
let tags = [];
|
|
15
|
+
try {
|
|
16
|
+
tags = JSON.parse(tagsAttribute.value.value);
|
|
17
|
+
}
|
|
18
|
+
catch (_c) {
|
|
19
|
+
if (((_b = (_a = tagsAttribute.value.data) === null || _a === void 0 ? void 0 : _a.estree) === null || _b === void 0 ? void 0 : _b.body.length) === 1) {
|
|
20
|
+
const body = tagsAttribute.value.data.estree.body[0];
|
|
21
|
+
if ((body === null || body === void 0 ? void 0 : body.type) === 'ExpressionStatement' && body.expression.type === 'ArrayExpression') {
|
|
22
|
+
tags = body.expression.elements
|
|
23
|
+
.map((element) => {
|
|
24
|
+
return (element === null || element === void 0 ? void 0 : element.type) === 'Literal' ? element.value : null;
|
|
25
|
+
})
|
|
26
|
+
.filter(Boolean);
|
|
38
27
|
}
|
|
39
28
|
}
|
|
40
29
|
}
|
|
30
|
+
if (!Array.isArray(tags)) {
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
tags.forEach((tag) => {
|
|
34
|
+
if (!!tag.trim()) {
|
|
35
|
+
tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
|
|
36
|
+
}
|
|
37
|
+
});
|
|
41
38
|
}
|
|
42
39
|
const filters = Array.from(tagCounts.entries())
|
|
43
40
|
.map(([tag, count]) => ({
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { MdxExtracts } from '../../../types/index.js';
|
|
3
|
+
export declare const remarkExtractTableOfContents: (mdxExtracts?: MdxExtracts) => (tree: Root) => void;
|
|
@@ -1,68 +1,84 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
-
import { createMdxJsxAttribute,
|
|
2
|
+
import { createMdxJsxAttribute, getTableOfContentsTitle, getUnicodeId, } from '../../lib/remark-utils.js';
|
|
3
|
+
import { HEADING_LEVELS } from './remarkHeadingIds.js';
|
|
4
|
+
const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
3
5
|
export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
4
6
|
// slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
|
|
5
7
|
// already exists. No counter is added for the first occurence.
|
|
6
8
|
const slugify = slugifyWithCounter();
|
|
7
9
|
return (tree) => {
|
|
10
|
+
var _a, _b, _c, _d;
|
|
8
11
|
const contents = [];
|
|
9
12
|
let hasTopLayer = false;
|
|
10
13
|
for (let nodeIndex = 0; nodeIndex < tree.children.length; nodeIndex++) {
|
|
11
|
-
|
|
12
|
-
if (
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
14
|
+
const node = tree.children[nodeIndex];
|
|
15
|
+
if (!node)
|
|
16
|
+
continue;
|
|
17
|
+
const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
|
|
18
|
+
const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
|
|
19
|
+
const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
|
|
20
|
+
node.name === 'Update' &&
|
|
21
|
+
node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
|
|
22
|
+
if (!isValidHeading && !isValidMdxHeading && !isValidUpdate) {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
let level;
|
|
26
|
+
if ('name' in node && node.name === 'Update') {
|
|
27
|
+
level = 1;
|
|
28
|
+
// @ts-expect-error we're assigning to depth despite the node not containing depth in the type
|
|
29
|
+
node.depth = 1;
|
|
30
|
+
}
|
|
31
|
+
else if ('depth' in node) {
|
|
32
|
+
level = node.depth;
|
|
33
|
+
}
|
|
34
|
+
else if ('name' in node && ((_b = node.name) === null || _b === void 0 ? void 0 : _b[1])) {
|
|
35
|
+
const num = Number(node.name[1]);
|
|
36
|
+
level = !isNaN(num) ? num : undefined;
|
|
37
|
+
}
|
|
38
|
+
const title = getTableOfContentsTitle(node);
|
|
39
|
+
const encodedTitle = getUnicodeId(title);
|
|
40
|
+
let slug;
|
|
41
|
+
// if encoded title is already percent-encoded, return it as is
|
|
42
|
+
// slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
|
|
43
|
+
if (/%[0-9A-F]{2}/.test(encodedTitle)) {
|
|
44
|
+
slug = slugify(encodedTitle, {
|
|
45
|
+
decamelize: false,
|
|
46
|
+
preserveCharacters: ['%'],
|
|
47
|
+
lowercase: false,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
slug = slugify(encodedTitle, { decamelize: false });
|
|
52
|
+
}
|
|
53
|
+
let mdxJsxAttributes;
|
|
54
|
+
if ('name' in node && node.name === 'Update') {
|
|
55
|
+
mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
|
|
56
|
+
}
|
|
57
|
+
else if (level !== undefined) {
|
|
58
|
+
mdxJsxAttributes = [
|
|
59
|
+
createMdxJsxAttribute('level', level),
|
|
60
|
+
createMdxJsxAttribute('id', slug),
|
|
61
|
+
createMdxJsxAttribute('isAtRootLevel', true),
|
|
62
|
+
];
|
|
63
|
+
}
|
|
64
|
+
// @ts-expect-error we're assigning over 'attributes' if it doesn't exist
|
|
65
|
+
node.attributes = mdxJsxAttributes;
|
|
66
|
+
node.type = 'mdxJsxFlowElement';
|
|
67
|
+
// @ts-expect-error we're assigning over 'name' if it doesn't exist
|
|
68
|
+
node.name = node.name === 'Update' ? 'Update' : 'Heading';
|
|
69
|
+
// @ts-expect-error we've already written to 'depth' and so this should be safe
|
|
70
|
+
const depth = node.depth;
|
|
71
|
+
if (level !== undefined && Number(level) <= 2) {
|
|
72
|
+
hasTopLayer = true;
|
|
73
|
+
contents.push({ title, slug, depth, children: [] });
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
// Account if there is no first layer
|
|
77
|
+
let arrToPushInto = contents;
|
|
78
|
+
if (hasTopLayer) {
|
|
79
|
+
arrToPushInto = (_d = (_c = contents.at(-1)) === null || _c === void 0 ? void 0 : _c.children) !== null && _d !== void 0 ? _d : [];
|
|
65
80
|
}
|
|
81
|
+
arrToPushInto.push({ title, slug, depth, children: [] });
|
|
66
82
|
}
|
|
67
83
|
}
|
|
68
84
|
if (mdxExtracts) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
export declare const remarkFrames: () => (tree: Root) => void;
|
|
@@ -1,37 +1,10 @@
|
|
|
1
|
-
import { toMdxJsxFlowElement } from '../../lib/remark-utils.js';
|
|
2
1
|
export const remarkFrames = () => {
|
|
3
2
|
return (tree) => {
|
|
4
|
-
let preTree = { children: [] };
|
|
5
3
|
tree.children = tree.children.map((node) => {
|
|
6
|
-
// Start of horizontal block: -- block
|
|
7
|
-
if (node.type === 'paragraph' &&
|
|
8
|
-
node.children.length === 1 &&
|
|
9
|
-
node.children[0].value === '-- block') {
|
|
10
|
-
node.type = 'jsx';
|
|
11
|
-
node.value = `<div className='grid md:grid-cols-2 md:gap-8'><div>`;
|
|
12
|
-
}
|
|
13
|
-
// Start a new column: -- column
|
|
14
|
-
if (node.type === 'paragraph' &&
|
|
15
|
-
node.children.length === 1 &&
|
|
16
|
-
node.children[0].value === '-- column') {
|
|
17
|
-
node.type = 'jsx';
|
|
18
|
-
node.value = `</div><div>`;
|
|
19
|
-
}
|
|
20
|
-
// End of horizontal block: -- /block
|
|
21
|
-
if (node.type === 'paragraph' &&
|
|
22
|
-
node.children.length === 1 &&
|
|
23
|
-
node.children[0].value === '-- /block') {
|
|
24
|
-
node.type = 'jsx';
|
|
25
|
-
node.value = `</div></div>`;
|
|
26
|
-
}
|
|
27
4
|
if (node.type === 'mdxJsxFlowElement' && (node.name === 'Example' || node.name === 'Frame')) {
|
|
28
5
|
node.name = 'Frame';
|
|
29
6
|
}
|
|
30
|
-
if (node.type === 'jsx') {
|
|
31
|
-
node = toMdxJsxFlowElement(node.value);
|
|
32
|
-
}
|
|
33
7
|
return node;
|
|
34
8
|
});
|
|
35
|
-
tree.children = [...preTree.children, ...tree.children];
|
|
36
9
|
};
|
|
37
10
|
};
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
2
|
import { visit } from 'unist-util-visit';
|
|
3
3
|
import { createMdxJsxAttribute, getUnicodeId } from '../../lib/remark-utils.js';
|
|
4
|
-
import {
|
|
4
|
+
import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
5
|
+
export const HEADING_LEVELS = [1, 2, 3, 4];
|
|
5
6
|
export const remarkHeadingIds = () => (tree) => {
|
|
6
7
|
const slugify = slugifyWithCounter();
|
|
7
8
|
visit(tree, 'heading', (node, _, parent) => {
|
|
8
|
-
if (
|
|
9
|
-
const title =
|
|
9
|
+
if (HEADING_LEVELS.includes(node.depth)) {
|
|
10
|
+
const title = getTableOfContentsTitle(node);
|
|
10
11
|
const encodedTitle = getUnicodeId(title);
|
|
11
12
|
let slug;
|
|
12
13
|
// if encoded title is already percent-encoded, return it as is
|
|
@@ -12,6 +12,10 @@ import { getAST } from '../../remark.js';
|
|
|
12
12
|
import { findExport } from './findExport.js';
|
|
13
13
|
import { injectToTopOfFileOfTree } from './injectToTopOfFile.js';
|
|
14
14
|
import { resolveComponentWithContent } from './resolveComponentWithContent.js';
|
|
15
|
+
const VALID_SPECIFIERS = [
|
|
16
|
+
MdxImportSpecifier.ImportSpecifier,
|
|
17
|
+
MdxImportSpecifier.RenamedImportSpecifier,
|
|
18
|
+
];
|
|
15
19
|
/**
|
|
16
20
|
*
|
|
17
21
|
* @param importSpecifier The name of the imported component we want to replace
|
|
@@ -20,7 +24,7 @@ import { resolveComponentWithContent } from './resolveComponentWithContent.js';
|
|
|
20
24
|
* @returns
|
|
21
25
|
*/
|
|
22
26
|
export const resolveImport = (importSpecifier, destinationPageContent, importedFileContent, exportMap) => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
if (
|
|
27
|
+
if (VALID_SPECIFIERS.includes(importSpecifier.type)) {
|
|
24
28
|
// normal import: import { Component } from '/snippets/Component.mdx'
|
|
25
29
|
if ((importSpecifier.renamedName && exportMap[importSpecifier.renamedName]) ||
|
|
26
30
|
exportMap[importSpecifier.name]) {
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { OpenAPIV3 } from 'openapi-types';
|
|
2
|
+
const VALID_METHODS = Object.values(OpenAPIV3.HttpMethods).concat('webhook');
|
|
1
3
|
/**
|
|
2
4
|
*
|
|
3
5
|
* @param str either the openapi or api string defined in the frontmatter
|
|
@@ -27,7 +29,7 @@ export const potentiallyParseOpenApiString = (str) => {
|
|
|
27
29
|
}
|
|
28
30
|
if (method) {
|
|
29
31
|
method = method.toLowerCase();
|
|
30
|
-
if (!
|
|
32
|
+
if (!VALID_METHODS.includes(method)) {
|
|
31
33
|
// invalid http method
|
|
32
34
|
return undefined;
|
|
33
35
|
}
|
|
@@ -63,7 +65,7 @@ export const parseOpenApiString = (str) => {
|
|
|
63
65
|
throw new Error('improperly formatted openapi string');
|
|
64
66
|
}
|
|
65
67
|
method = method.toLowerCase();
|
|
66
|
-
if (!
|
|
68
|
+
if (!VALID_METHODS.includes(method)) {
|
|
67
69
|
throw new Error('invalid http method');
|
|
68
70
|
}
|
|
69
71
|
return {
|