@mintlify/common 1.0.1016 → 1.0.1018
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/plugins/remark/remarkExtractTableOfContents.js +28 -10
- package/dist/mdx/plugins/remark/remarkValidateSteps.js +11 -7
- package/dist/mdx/utils.d.ts +1 -0
- package/dist/mdx/utils.js +1 -0
- package/dist/slugify.d.ts +1 -0
- package/dist/slugify.js +10 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
|
-
import { slugify } from '../../../slugify.js';
|
|
2
|
+
import { safeCleanHeadingId, slugify } from '../../../slugify.js';
|
|
3
3
|
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
4
|
+
import { isMdxJsxFragment } from '../../utils.js';
|
|
4
5
|
import { AVOIDED_PAGE_MODES, HEADING_LEVELS } from './remarkComponentIds.js';
|
|
5
6
|
export const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
6
7
|
const COMPONENTS_TO_EXCLUDE_HEADINGS = [
|
|
@@ -55,15 +56,25 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
55
56
|
if (node.type === 'mdxJsxFlowElement' && node.name === 'Steps') {
|
|
56
57
|
const stepsTitleSize = getStringAttribute(node.attributes, 'titleSize');
|
|
57
58
|
if (stepsTitleSize) {
|
|
58
|
-
// At render time <Steps>
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
59
|
+
// At render time <Steps> forwards titleSize to its immediate child
|
|
60
|
+
// <Step>s and flattens fragments, so mirror both here. Fragments
|
|
61
|
+
// parse as name-less mdxJsxFlowElements and are transparent;
|
|
62
|
+
// assigning to every descendant would leak the value into a nested
|
|
63
|
+
// <Steps> and its own steps even when that inner wrapper sets no
|
|
64
|
+
// (or a different) titleSize.
|
|
65
|
+
const assignInheritedTitleSize = (children) => {
|
|
66
|
+
for (const childNode of children) {
|
|
67
|
+
if (childNode.type !== 'mdxJsxFlowElement')
|
|
68
|
+
continue;
|
|
69
|
+
if (childNode.name === 'Step') {
|
|
70
|
+
inheritedStepTitleSizeMap.set(childNode, stepsTitleSize);
|
|
71
|
+
}
|
|
72
|
+
else if (isMdxJsxFragment(childNode)) {
|
|
73
|
+
assignInheritedTitleSize(childNode.children);
|
|
74
|
+
}
|
|
65
75
|
}
|
|
66
|
-
}
|
|
76
|
+
};
|
|
77
|
+
assignInheritedTitleSize(node.children);
|
|
67
78
|
}
|
|
68
79
|
}
|
|
69
80
|
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
@@ -100,8 +111,15 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
100
111
|
const stepTitleSize = node.type === 'mdxJsxFlowElement' && node.name === 'Step'
|
|
101
112
|
? ((_b = getStringAttribute(node.attributes, 'titleSize')) !== null && _b !== void 0 ? _b : inheritedStepTitleSizeMap.get(node))
|
|
102
113
|
: undefined;
|
|
114
|
+
const hasNoAnchor = node.type === 'mdxJsxFlowElement' &&
|
|
115
|
+
node.attributes.some((attr) => 'name' in attr &&
|
|
116
|
+
attr.name === 'noAnchor' &&
|
|
117
|
+
(attr.value == null ||
|
|
118
|
+
attr.value === 'true' ||
|
|
119
|
+
(typeof attr.value === 'object' && attr.value.value === 'true')));
|
|
103
120
|
const isValidStep = node.type === 'mdxJsxFlowElement' &&
|
|
104
121
|
node.name === 'Step' &&
|
|
122
|
+
!hasNoAnchor &&
|
|
105
123
|
['h2', 'h3'].includes(stepTitleSize !== null && stepTitleSize !== void 0 ? stepTitleSize : '') &&
|
|
106
124
|
((_d = (_c = getStringAttribute(node.attributes, 'title')) === null || _c === void 0 ? void 0 : _c.trim()) !== null && _d !== void 0 ? _d : '') !== '';
|
|
107
125
|
const hasIdAttribute = node.type === 'mdxJsxFlowElement' &&
|
|
@@ -159,7 +177,7 @@ export const remarkExtractTableOfContents = (mdxExtracts, pageMetadata) => {
|
|
|
159
177
|
? getStringAttribute(node.attributes, 'id')
|
|
160
178
|
: undefined;
|
|
161
179
|
if (explicitId) {
|
|
162
|
-
slug = deduplicateSlug(explicitId);
|
|
180
|
+
slug = deduplicateSlug(safeCleanHeadingId(explicitId) || slugify(title));
|
|
163
181
|
}
|
|
164
182
|
else {
|
|
165
183
|
slug = deduplicateSlug(slugify(title));
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { visitParents } from 'unist-util-visit-parents';
|
|
2
|
+
import { isMdxJsxFlowElement, isMdxJsxFragment } from '../../utils.js';
|
|
2
3
|
export const remarkValidateSteps = () => (tree) => {
|
|
3
|
-
|
|
4
|
-
if (node.name
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
visitParents(tree, 'mdxJsxFlowElement', (node, ancestors) => {
|
|
5
|
+
if (node.name !== 'Step')
|
|
6
|
+
return;
|
|
7
|
+
// Fragments are transparent: <Steps> flattens them at render time.
|
|
8
|
+
const meaningfulAncestors = ancestors.filter((ancestor) => !isMdxJsxFragment(ancestor));
|
|
9
|
+
const parent = meaningfulAncestors[meaningfulAncestors.length - 1];
|
|
10
|
+
const parentIsSteps = parent !== undefined && isMdxJsxFlowElement(parent) && parent.name === 'Steps';
|
|
11
|
+
if (!parentIsSteps) {
|
|
12
|
+
console.warn('Please ensure that all <Step> components are direct children of <Steps>.');
|
|
9
13
|
}
|
|
10
14
|
});
|
|
11
15
|
};
|
package/dist/mdx/utils.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare const isImportDeclaration: (bodyChild: MdxNodeBodyChildType) => b
|
|
|
13
13
|
export declare const isExport: (type: string) => boolean;
|
|
14
14
|
export declare const isExportNode: (bodyChild: MdxNodeBodyChildType) => bodyChild is ExportAllDeclaration | ExportDefaultDeclaration | ExportNamedDeclaration;
|
|
15
15
|
export declare const isMdxJsxFlowElement: (node: Node) => node is MdxJsxFlowElement;
|
|
16
|
+
export declare const isMdxJsxFragment: (node: Node) => node is MdxJsxFlowElement;
|
|
16
17
|
export declare const createUniqueVariableName: (variableName: string, id: number) => string;
|
|
17
18
|
export declare const getObjectExpressionStringProperty: (key: string, attribute: MdxJsxAttribute | MdxJsxExpressionAttribute | undefined) => string | undefined;
|
|
18
19
|
export declare const getArrayExpressionStringProperties: (attribute: MdxJsxAttribute | MdxJsxExpressionAttribute | undefined) => string[];
|
package/dist/mdx/utils.js
CHANGED
|
@@ -11,6 +11,7 @@ export const isExport = (type) => [
|
|
|
11
11
|
].includes(type);
|
|
12
12
|
export const isExportNode = (bodyChild) => isExport(bodyChild.type);
|
|
13
13
|
export const isMdxJsxFlowElement = (node) => node.type === 'mdxJsxFlowElement';
|
|
14
|
+
export const isMdxJsxFragment = (node) => isMdxJsxFlowElement(node) && node.name == null;
|
|
14
15
|
export const createUniqueVariableName = (variableName, id) => `${variableName}_${id}`;
|
|
15
16
|
export const getObjectExpressionStringProperty = (key, attribute) => {
|
|
16
17
|
var _a, _b, _c;
|
package/dist/slugify.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { CountableSlugify } from '@sindresorhus/slugify';
|
|
2
2
|
export declare const cleanHeadingId: (id: string) => string;
|
|
3
|
+
export declare const safeCleanHeadingId: (id: string) => string;
|
|
3
4
|
export declare function slugify(string: string, slugify?: CountableSlugify): string;
|
package/dist/slugify.js
CHANGED
|
@@ -8,6 +8,16 @@ export const cleanHeadingId = (id) => {
|
|
|
8
8
|
.replace(/[?,;:!'"()[\]{}]/g, '')
|
|
9
9
|
.replace(/\p{Emoji_Modifier}|\p{Emoji_Modifier_Base}|\p{Emoji_Presentation}|\p{Extended_Pictographic}|[\u200D\uFE0E\uFE0F]/gu, '');
|
|
10
10
|
};
|
|
11
|
+
// decodeURIComponent throws on malformed percent sequences (e.g. an author id
|
|
12
|
+
// of "100%1"); fall back to the raw id instead of crashing the render/compile
|
|
13
|
+
export const safeCleanHeadingId = (id) => {
|
|
14
|
+
try {
|
|
15
|
+
return cleanHeadingId(id);
|
|
16
|
+
}
|
|
17
|
+
catch (_a) {
|
|
18
|
+
return id;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
11
21
|
export function slugify(string, slugify = slugifyWithCounter()) {
|
|
12
22
|
const encodedString = getUnicodeId(string);
|
|
13
23
|
// if encoded title is already percent-encoded, return it as is
|