@mintlify/common 1.0.1015 → 1.0.1017

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.
@@ -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> only forwards titleSize to its immediate
59
- // child <Step>s, so mirror that here. Assigning to every descendant
60
- // would leak the value into a nested <Steps> and its own steps even
61
- // when that inner wrapper sets no (or a different) titleSize.
62
- for (const childNode of node.children) {
63
- if (childNode.type === 'mdxJsxFlowElement' && childNode.name === 'Step') {
64
- inheritedStepTitleSizeMap.set(childNode, stepsTitleSize);
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,10 +1,10 @@
1
+ import { visit } from 'unist-util-visit';
1
2
  export const remarkFrames = () => {
2
3
  return (tree) => {
3
- tree.children = tree.children.map((node) => {
4
- if (node.type === 'mdxJsxFlowElement' && (node.name === 'Example' || node.name === 'Frame')) {
4
+ visit(tree, 'mdxJsxFlowElement', (node) => {
5
+ if (node.name === 'Example') {
5
6
  node.name = 'Frame';
6
7
  }
7
- return node;
8
8
  });
9
9
  };
10
10
  };
@@ -1,11 +1,15 @@
1
- import { visit } from 'unist-util-visit';
1
+ import { visitParents } from 'unist-util-visit-parents';
2
+ import { isMdxJsxFlowElement, isMdxJsxFragment } from '../../utils.js';
2
3
  export const remarkValidateSteps = () => (tree) => {
3
- visit(tree, 'mdxJsxFlowElement', (node, _idx, parent) => {
4
- if (node.name === 'Step') {
5
- const parentElement = parent;
6
- if (!parentElement || parentElement.name !== 'Steps') {
7
- console.warn('Please ensure that all <Step> components are direct children of <Steps>.');
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
  };
@@ -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