@mintlify/common 1.0.463 → 1.0.465
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 +2 -2
- package/dist/mdx/plugins/rehype/rehypeUnicodeIds.js +1 -1
- package/dist/mdx/plugins/remark/index.d.ts +1 -1
- package/dist/mdx/plugins/remark/index.js +1 -1
- package/dist/mdx/plugins/remark/{remarkHeadingIds.d.ts → remarkComponentIds.d.ts} +1 -1
- package/dist/mdx/plugins/remark/remarkComponentIds.js +87 -0
- package/dist/mdx/plugins/remark/remarkExtractTableOfContents.js +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/dist/mdx/plugins/remark/remarkHeadingIds.js +0 -26
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames,
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, } from './plugins/index.js';
|
|
2
2
|
import { remarkMdxRemoveUnknownJsx } from './plugins/remark/remarkMdxRemoveUnknownJsx/index.js';
|
|
3
3
|
import { remarkMermaid } from './plugins/remark/remarkMermaid.js';
|
|
4
4
|
// avoid running extractors unnecessarily
|
|
@@ -21,7 +21,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
21
21
|
remarkFrames,
|
|
22
22
|
remarkRemoveImports,
|
|
23
23
|
remarkMermaid,
|
|
24
|
-
|
|
24
|
+
remarkComponentIds,
|
|
25
25
|
...remarkPlugins,
|
|
26
26
|
[remarkMdxRemoveUnknownJsx, data.allowedComponents],
|
|
27
27
|
],
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { visit } from 'unist-util-visit';
|
|
2
2
|
import { getUnicodeId, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
3
|
-
const DEEPLINKABLE_COMPONENTS = ['Heading', 'Update', 'Accordion'];
|
|
3
|
+
const DEEPLINKABLE_COMPONENTS = ['Heading', 'Update', 'Accordion', 'Tab'];
|
|
4
4
|
export const rehypeUnicodeIds = () => {
|
|
5
5
|
return (tree) => {
|
|
6
6
|
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
@@ -11,7 +11,7 @@ export * from './remarkExtractChangelogFilters.js';
|
|
|
11
11
|
export * from './remarkExpandContent.js';
|
|
12
12
|
export * from './remarkSplitCodeGroup.js';
|
|
13
13
|
export * from './remarkSplitTabs.js';
|
|
14
|
-
export * from './
|
|
14
|
+
export * from './remarkComponentIds.js';
|
|
15
15
|
export * from './remarkMdxExtractPanel.js';
|
|
16
16
|
export * from './remarkValidateSteps.js';
|
|
17
17
|
export * from './remarkValidateTabs.js';
|
|
@@ -11,7 +11,7 @@ export * from './remarkExtractChangelogFilters.js';
|
|
|
11
11
|
export * from './remarkExpandContent.js';
|
|
12
12
|
export * from './remarkSplitCodeGroup.js';
|
|
13
13
|
export * from './remarkSplitTabs.js';
|
|
14
|
-
export * from './
|
|
14
|
+
export * from './remarkComponentIds.js';
|
|
15
15
|
export * from './remarkMdxExtractPanel.js';
|
|
16
16
|
export * from './remarkValidateSteps.js';
|
|
17
17
|
export * from './remarkValidateTabs.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { slugify } from '../../../slugify.js';
|
|
4
|
+
import { createMdxJsxAttribute } from '../../lib/remark-utils.js';
|
|
5
|
+
import { getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
6
|
+
export const HEADING_LEVELS = [1, 2, 3, 4];
|
|
7
|
+
export const remarkComponentIds = () => (tree) => {
|
|
8
|
+
const slugifyFn = slugifyWithCounter();
|
|
9
|
+
const tabSlugifyFn = slugifyWithCounter();
|
|
10
|
+
visit(tree, 'heading', (node, _, parent) => {
|
|
11
|
+
if (HEADING_LEVELS.includes(node.depth)) {
|
|
12
|
+
const title = getTableOfContentsTitle(node);
|
|
13
|
+
const slug = slugify(title, slugifyFn);
|
|
14
|
+
const mdxJsxAttributes = [
|
|
15
|
+
createMdxJsxAttribute('level', node.depth),
|
|
16
|
+
createMdxJsxAttribute('id', slug),
|
|
17
|
+
createMdxJsxAttribute('isAtRootLevel', (parent === null || parent === void 0 ? void 0 : parent.type) === 'root'),
|
|
18
|
+
];
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
+
node.attributes = mdxJsxAttributes;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
node.type = 'mdxJsxFlowElement';
|
|
23
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
|
+
node.name = 'Heading';
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
const tabSlugs = new Map();
|
|
28
|
+
const precomputeTabSlugs = (node) => {
|
|
29
|
+
var _a;
|
|
30
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
31
|
+
const title = (_a = node.attributes.find((attr) => 'name' in attr && attr.name === 'title')) === null || _a === void 0 ? void 0 : _a.value;
|
|
32
|
+
if (title && typeof title === 'string') {
|
|
33
|
+
const slug = slugify(title, tabSlugifyFn);
|
|
34
|
+
tabSlugs.set(node, slug);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if ('children' in node) {
|
|
38
|
+
for (const child of node.children) {
|
|
39
|
+
precomputeTabSlugs(child);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const processTabsRecursively = (node) => {
|
|
44
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
45
|
+
const slug = tabSlugs.get(node);
|
|
46
|
+
if (!slug)
|
|
47
|
+
return;
|
|
48
|
+
node.attributes.push(createMdxJsxAttribute('id', slug));
|
|
49
|
+
const childTabIds = [];
|
|
50
|
+
for (const child of node.children) {
|
|
51
|
+
const childIds = collectDirectChildTabs(child);
|
|
52
|
+
childTabIds.push(...childIds);
|
|
53
|
+
}
|
|
54
|
+
if (childTabIds.length > 0) {
|
|
55
|
+
try {
|
|
56
|
+
node.attributes.push(createMdxJsxAttribute('data-child-tab-ids', JSON.stringify(childTabIds)));
|
|
57
|
+
}
|
|
58
|
+
catch (_a) { }
|
|
59
|
+
}
|
|
60
|
+
for (const child of node.children) {
|
|
61
|
+
processTabsRecursively(child);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
else if ('children' in node) {
|
|
65
|
+
for (const child of node.children) {
|
|
66
|
+
processTabsRecursively(child);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const collectDirectChildTabs = (node) => {
|
|
71
|
+
const childIds = [];
|
|
72
|
+
if (node.type === 'mdxJsxFlowElement' && node.name === 'Tab') {
|
|
73
|
+
const slug = tabSlugs.get(node);
|
|
74
|
+
if (slug) {
|
|
75
|
+
childIds.push(slug);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
else if ('children' in node) {
|
|
79
|
+
for (const child of node.children) {
|
|
80
|
+
childIds.push(...collectDirectChildTabs(child));
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return childIds;
|
|
84
|
+
};
|
|
85
|
+
precomputeTabSlugs(tree);
|
|
86
|
+
processTabsRecursively(tree);
|
|
87
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
2
|
import { slugify } from '../../../slugify.js';
|
|
3
3
|
import { createMdxJsxAttribute, getTableOfContentsTitle } from '../../lib/remark-utils.js';
|
|
4
|
-
import { HEADING_LEVELS } from './
|
|
4
|
+
import { HEADING_LEVELS } from './remarkComponentIds.js';
|
|
5
5
|
const HEADING_NAMES = ['h1', 'h2', 'h3', 'h4'];
|
|
6
6
|
export const remarkExtractTableOfContents = (mdxExtracts) => {
|
|
7
7
|
// slugifyWithCounter adds a counter (eg. slug, slug-2, slug-3) to the end of the slug if the header
|