@mintlify/common 1.0.528 → 1.0.530
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.
|
@@ -2,4 +2,6 @@ import type { PageMetaTags } from '@mintlify/models';
|
|
|
2
2
|
import type { Root } from 'mdast';
|
|
3
3
|
export declare const HEADING_LEVELS: number[];
|
|
4
4
|
export declare const AVOIDED_PAGE_MODES: string[];
|
|
5
|
+
export declare const CHILD_TAB_IDS_ATTRIBUTE = "data-child-tab-ids";
|
|
6
|
+
export declare const CHILD_HEADING_IDS_ATTRIBUTE = "data-child-heading-ids";
|
|
5
7
|
export declare const remarkComponentIds: (pageMetadata?: PageMetaTags) => (tree: Root) => void;
|
|
@@ -5,6 +5,8 @@ import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
|
|
|
5
5
|
import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
6
6
|
export const HEADING_LEVELS = [1, 2, 3, 4];
|
|
7
7
|
export const AVOIDED_PAGE_MODES = ['custom', 'frame'];
|
|
8
|
+
export const CHILD_TAB_IDS_ATTRIBUTE = 'data-child-tab-ids';
|
|
9
|
+
export const CHILD_HEADING_IDS_ATTRIBUTE = 'data-child-heading-ids';
|
|
8
10
|
export const remarkComponentIds = (pageMetadata) => (tree) => {
|
|
9
11
|
var _a;
|
|
10
12
|
const slugifyFn = slugifyWithCounter();
|
|
@@ -29,8 +31,9 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
|
|
|
29
31
|
}
|
|
30
32
|
});
|
|
31
33
|
const tabSlugs = new Map();
|
|
34
|
+
const headingSlugs = new Map();
|
|
32
35
|
const precomputeTabSlugs = (node) => {
|
|
33
|
-
var _a;
|
|
36
|
+
var _a, _b;
|
|
34
37
|
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
35
38
|
const title = (_a = node.attributes.find((attr) => 'name' in attr && attr.name === 'title')) === null || _a === void 0 ? void 0 : _a.value;
|
|
36
39
|
if (title && typeof title === 'string') {
|
|
@@ -38,6 +41,11 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
|
|
|
38
41
|
tabSlugs.set(node, slug);
|
|
39
42
|
}
|
|
40
43
|
}
|
|
44
|
+
else if (node.type === 'mdxJsxFlowElement' && node.name === 'Heading') {
|
|
45
|
+
const id = (_b = node.attributes.find((attr) => 'name' in attr && attr.name === 'id')) === null || _b === void 0 ? void 0 : _b.value;
|
|
46
|
+
if (id && typeof id === 'string')
|
|
47
|
+
headingSlugs.set(node, id);
|
|
48
|
+
}
|
|
41
49
|
if ('children' in node) {
|
|
42
50
|
for (const child of node.children) {
|
|
43
51
|
precomputeTabSlugs(child);
|
|
@@ -52,15 +60,22 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
|
|
|
52
60
|
node.attributes.push(createMdxJsxAttribute('id', slug));
|
|
53
61
|
const childTabIds = [];
|
|
54
62
|
for (const child of node.children) {
|
|
55
|
-
const childIds =
|
|
63
|
+
const childIds = collectDirectChildIds(child, 'Tab');
|
|
56
64
|
childTabIds.push(...childIds);
|
|
57
65
|
}
|
|
58
66
|
if (childTabIds.length > 0) {
|
|
59
67
|
try {
|
|
60
|
-
node.attributes.push(createMdxJsxAttribute(
|
|
68
|
+
node.attributes.push(createMdxJsxAttribute(CHILD_TAB_IDS_ATTRIBUTE, JSON.stringify(childTabIds)));
|
|
61
69
|
}
|
|
62
70
|
catch (_a) { }
|
|
63
71
|
}
|
|
72
|
+
const childHeadingIds = collectDirectChildIds(node, 'Heading');
|
|
73
|
+
if (childHeadingIds.length > 0) {
|
|
74
|
+
try {
|
|
75
|
+
node.attributes.push(createMdxJsxAttribute(CHILD_HEADING_IDS_ATTRIBUTE, JSON.stringify(childHeadingIds)));
|
|
76
|
+
}
|
|
77
|
+
catch (_b) { }
|
|
78
|
+
}
|
|
64
79
|
for (const child of node.children) {
|
|
65
80
|
processTabsRecursively(child);
|
|
66
81
|
}
|
|
@@ -71,17 +86,17 @@ export const remarkComponentIds = (pageMetadata) => (tree) => {
|
|
|
71
86
|
}
|
|
72
87
|
}
|
|
73
88
|
};
|
|
74
|
-
const
|
|
89
|
+
const collectDirectChildIds = (node, type) => {
|
|
75
90
|
const childIds = [];
|
|
76
|
-
if (node.type === 'mdxJsxFlowElement' && node.name ===
|
|
77
|
-
const
|
|
78
|
-
if (
|
|
79
|
-
childIds.push(
|
|
91
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === type) {
|
|
92
|
+
const id = type === 'Tab' ? tabSlugs.get(node) : headingSlugs.get(node);
|
|
93
|
+
if (id) {
|
|
94
|
+
childIds.push(id);
|
|
80
95
|
}
|
|
81
96
|
}
|
|
82
97
|
else if ('children' in node) {
|
|
83
98
|
for (const child of node.children) {
|
|
84
|
-
childIds.push(...
|
|
99
|
+
childIds.push(...collectDirectChildIds(child, type));
|
|
85
100
|
}
|
|
86
101
|
}
|
|
87
102
|
return childIds;
|