@mintlify/common 1.0.740 → 1.0.742

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,2 +1,3 @@
1
1
  import type { Root } from 'hast';
2
+ export declare function generateParamFieldId(name: string, count: number): string;
2
3
  export declare const rehypeParamFieldIds: () => (tree: Root) => Root;
@@ -1,5 +1,9 @@
1
1
  import slugify from '@sindresorhus/slugify';
2
2
  import { visit } from 'unist-util-visit';
3
+ export function generateParamFieldId(name, count) {
4
+ const suffix = count > 0 ? `_${count}` : '';
5
+ return slugify(`param-${name}${suffix}`, { decamelize: true, separator: '-' });
6
+ }
3
7
  export const rehypeParamFieldIds = () => {
4
8
  return (tree) => {
5
9
  const paramCounts = new Map();
@@ -17,11 +21,7 @@ export const rehypeParamFieldIds = () => {
17
21
  if (nameAttr && typeof nameAttr.value === 'string' && nameAttr.value) {
18
22
  const currentCount = (_a = paramCounts.get(nameAttr.value)) !== null && _a !== void 0 ? _a : 0;
19
23
  paramCounts.set(nameAttr.value, currentCount + 1);
20
- const suffix = currentCount > 0 ? `_${currentCount}` : '';
21
- const id = slugify(`param-${nameAttr.value}${suffix}`, {
22
- decamelize: true,
23
- separator: '-',
24
- });
24
+ const id = generateParamFieldId(nameAttr.value, currentCount);
25
25
  element.attributes.push({
26
26
  type: 'mdxJsxAttribute',
27
27
  name: 'id',
@@ -1,5 +1,6 @@
1
1
  import type { PageMetaTags } from '@mintlify/models';
2
2
  import type { Root } from 'mdast';
3
+ export declare function generateAccordionId(title: string, count?: number): string;
3
4
  export declare const HEADING_LEVELS: number[];
4
5
  export declare const AVOIDED_PAGE_MODES: string[];
5
6
  export declare const CHILD_TAB_IDS_ATTRIBUTE = "data-child-tab-ids";
@@ -1,8 +1,12 @@
1
- import { slugifyWithCounter } from '@sindresorhus/slugify';
1
+ import defaultSlugify, { slugifyWithCounter } from '@sindresorhus/slugify';
2
2
  import { visit } from 'unist-util-visit';
3
3
  import { slugify } from '../../../slugify.js';
4
4
  import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
5
5
  import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
6
+ export function generateAccordionId(title, count) {
7
+ const base = defaultSlugify(title.replace(':', '-'), { decamelize: false });
8
+ return count != null && count > 0 ? `${base}-${count}` : base;
9
+ }
6
10
  export const HEADING_LEVELS = [1, 2, 3, 4];
7
11
  export const AVOIDED_PAGE_MODES = ['custom', 'frame'];
8
12
  export const CHILD_TAB_IDS_ATTRIBUTE = 'data-child-tab-ids';
@@ -103,4 +107,20 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
103
107
  };
104
108
  precomputeTabSlugs(tree);
105
109
  processTabsRecursively(tree);
110
+ const accordionCounts = new Map();
111
+ visit(tree, 'mdxJsxFlowElement', (node) => {
112
+ var _a;
113
+ if (node.name !== 'Accordion')
114
+ return;
115
+ const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
116
+ if (!titleAttr || typeof titleAttr.value !== 'string' || !titleAttr.value)
117
+ return;
118
+ const hasId = node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
119
+ if (hasId)
120
+ return;
121
+ const title = titleAttr.value;
122
+ const count = (_a = accordionCounts.get(title)) !== null && _a !== void 0 ? _a : 0;
123
+ accordionCounts.set(title, count + 1);
124
+ node.attributes.push(createMdxJsxAttribute('id', generateAccordionId(title, count)));
125
+ });
106
126
  };