@mintlify/common 1.0.485 → 1.0.487
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/getMDXOptions.js +1 -1
- package/dist/mdx/plugins/remark/remarkComponentIds.js +1 -2
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +58 -13
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mdx/TableOfContentsSectionType.d.ts +1 -0
- package/package.json +2 -2
|
@@ -14,6 +14,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
14
14
|
return {
|
|
15
15
|
remarkPlugins: [
|
|
16
16
|
[remarkMdxInjectSnippets, data.snippetTreeMap],
|
|
17
|
+
remarkComponentIds,
|
|
17
18
|
[remarkExtractTableOfContents, mdxExtracts], // modifies tree so cannot be excluded
|
|
18
19
|
[remarkExtractChangelogFilters, mdxExtracts],
|
|
19
20
|
[remarkMdxExtractPanel, mdxExtracts],
|
|
@@ -21,7 +22,6 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
21
22
|
remarkFrames,
|
|
22
23
|
remarkRemoveImports,
|
|
23
24
|
remarkMermaid,
|
|
24
|
-
remarkComponentIds,
|
|
25
25
|
...remarkPlugins,
|
|
26
26
|
remarkMdxRemoveUnknownJsx,
|
|
27
27
|
],
|
|
@@ -7,14 +7,13 @@ export const HEADING_LEVELS = [1, 2, 3, 4];
|
|
|
7
7
|
export const remarkComponentIds = () => (tree) => {
|
|
8
8
|
const slugifyFn = slugifyWithCounter();
|
|
9
9
|
const tabSlugifyFn = slugifyWithCounter();
|
|
10
|
-
visit(tree, 'heading', (node
|
|
10
|
+
visit(tree, 'heading', (node) => {
|
|
11
11
|
if (HEADING_LEVELS.includes(node.depth)) {
|
|
12
12
|
const title = getTableOfContentsTitle(node);
|
|
13
13
|
const slug = slugify(title, slugifyFn);
|
|
14
14
|
const mdxJsxAttributes = [
|
|
15
15
|
createMdxJsxAttribute('level', node.depth),
|
|
16
16
|
createMdxJsxAttribute('id', slug),
|
|
17
|
-
createMdxJsxAttribute('isAtRootLevel', (parent === null || parent === void 0 ? void 0 : parent.type) === 'root'),
|
|
18
17
|
];
|
|
19
18
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
19
|
node.attributes = mdxJsxAttributes;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
2
3
|
import { slugify } from '../../../slugify.js';
|
|
3
4
|
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
4
5
|
import { HEADING_LEVELS } from './remarkComponentIds.js';
|
|
@@ -8,20 +9,41 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
|
8
9
|
// already exists. No counter is added for the first occurence.
|
|
9
10
|
const slugifyFn = slugifyWithCounter();
|
|
10
11
|
return (tree) => {
|
|
11
|
-
var _a, _b, _c, _d;
|
|
12
12
|
const contents = [];
|
|
13
13
|
let hasTopLayer = false;
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
// the key is the node in unist
|
|
15
|
+
const tabContentMap = new Map();
|
|
16
|
+
visit(tree, (node) => {
|
|
17
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
18
|
+
const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
|
|
19
|
+
const titleAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'title');
|
|
20
|
+
let tabId;
|
|
21
|
+
if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
|
|
22
|
+
tabId = idAttr.value;
|
|
23
|
+
}
|
|
24
|
+
else if (titleAttr && 'value' in titleAttr && typeof titleAttr.value === 'string') {
|
|
25
|
+
tabId = slugify(titleAttr.value);
|
|
26
|
+
}
|
|
27
|
+
if (tabId) {
|
|
28
|
+
visit(node, (childNode) => {
|
|
29
|
+
tabContentMap.set(childNode, tabId);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
visit(tree, (node) => {
|
|
35
|
+
var _a, _b, _c, _d;
|
|
36
|
+
const currentTabId = tabContentMap.get(node);
|
|
18
37
|
const isValidHeading = node.type === 'heading' && HEADING_LEVELS.includes(node.depth);
|
|
19
38
|
const isValidMdxHeading = node.type === 'mdxJsxFlowElement' && HEADING_NAMES.includes((_a = node.name) !== null && _a !== void 0 ? _a : '');
|
|
39
|
+
const isTransformedHeading = node.type === 'mdxJsxFlowElement' && node.name === 'Heading';
|
|
20
40
|
const isValidUpdate = node.type === 'mdxJsxFlowElement' &&
|
|
21
41
|
node.name === 'Update' &&
|
|
22
42
|
node.attributes.some((attr) => 'name' in attr && attr.name === 'label');
|
|
23
|
-
|
|
24
|
-
|
|
43
|
+
const hasIdAttribute = node.type === 'mdxJsxFlowElement' &&
|
|
44
|
+
node.attributes.some((attr) => 'name' in attr && attr.name === 'id');
|
|
45
|
+
if (!isValidHeading && !isValidMdxHeading && !isTransformedHeading && !isValidUpdate) {
|
|
46
|
+
return;
|
|
25
47
|
}
|
|
26
48
|
let level;
|
|
27
49
|
if ('name' in node && node.name === 'Update') {
|
|
@@ -32,22 +54,45 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
|
32
54
|
else if ('depth' in node) {
|
|
33
55
|
level = node.depth;
|
|
34
56
|
}
|
|
57
|
+
else if ('name' in node && node.name === 'Heading') {
|
|
58
|
+
const levelAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'level');
|
|
59
|
+
if (levelAttr && 'value' in levelAttr && typeof levelAttr.value === 'number') {
|
|
60
|
+
level = levelAttr.value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
35
63
|
else if ('name' in node && ((_b = node.name) === null || _b === void 0 ? void 0 : _b[1])) {
|
|
36
64
|
const num = Number(node.name[1]);
|
|
37
65
|
level = !isNaN(num) ? num : undefined;
|
|
38
66
|
}
|
|
39
67
|
const title = getTableOfContentsTitle(node);
|
|
40
|
-
|
|
68
|
+
let slug;
|
|
69
|
+
if ('name' in node && node.name === 'Heading') {
|
|
70
|
+
const idAttr = node.attributes.find((attr) => 'name' in attr && attr.name === 'id');
|
|
71
|
+
if (idAttr && 'value' in idAttr && typeof idAttr.value === 'string') {
|
|
72
|
+
slug = idAttr.value;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
slug = slugify(title, slugifyFn);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
slug = slugify(title, slugifyFn);
|
|
80
|
+
}
|
|
41
81
|
let mdxJsxAttributes;
|
|
42
82
|
if ('name' in node && node.name === 'Update') {
|
|
43
83
|
mdxJsxAttributes = [...node.attributes, createMdxJsxAttribute('id', slug)];
|
|
44
84
|
}
|
|
45
|
-
else if (
|
|
85
|
+
else if ('name' in node && node.name === 'Heading') {
|
|
86
|
+
mdxJsxAttributes = node.attributes;
|
|
87
|
+
}
|
|
88
|
+
else if (level !== undefined && !hasIdAttribute) {
|
|
46
89
|
mdxJsxAttributes = [
|
|
47
90
|
createMdxJsxAttribute('level', level),
|
|
48
91
|
createMdxJsxAttribute('id', slug),
|
|
49
|
-
createMdxJsxAttribute('isAtRootLevel', true),
|
|
50
92
|
];
|
|
93
|
+
if (isValidMdxHeading && node.attributes.length > 0) {
|
|
94
|
+
mdxJsxAttributes.push(...node.attributes);
|
|
95
|
+
}
|
|
51
96
|
}
|
|
52
97
|
// @ts-expect-error we're assigning over 'attributes' if it doesn't exist
|
|
53
98
|
node.attributes = mdxJsxAttributes;
|
|
@@ -58,7 +103,7 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
|
58
103
|
const depth = node.depth;
|
|
59
104
|
if (level !== undefined && Number(level) <= 2) {
|
|
60
105
|
hasTopLayer = true;
|
|
61
|
-
contents.push({ title, slug, depth, children: [] });
|
|
106
|
+
contents.push({ title, slug, depth, children: [], tabId: currentTabId });
|
|
62
107
|
}
|
|
63
108
|
else {
|
|
64
109
|
// Account if there is no first layer
|
|
@@ -66,9 +111,9 @@ export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
|
66
111
|
if (hasTopLayer) {
|
|
67
112
|
arrToPushInto = (_d = (_c = contents.at(-1)) === null || _c === void 0 ? void 0 : _c.children) !== null && _d !== void 0 ? _d : [];
|
|
68
113
|
}
|
|
69
|
-
arrToPushInto.push({ title, slug, depth, children: [] });
|
|
114
|
+
arrToPushInto.push({ title, slug, depth, children: [], tabId: currentTabId });
|
|
70
115
|
}
|
|
71
|
-
}
|
|
116
|
+
});
|
|
72
117
|
if (mdxExtracts) {
|
|
73
118
|
mdxExtracts.tableOfContents = contents;
|
|
74
119
|
}
|