@mintlify/common 1.0.335 → 1.0.336
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 -1
- package/dist/mdx/plugins/remark/index.d.ts +1 -0
- package/dist/mdx/plugins/remark/index.js +1 -0
- package/dist/mdx/plugins/remark/remarkHeadingIds.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkHeadingIds.js +36 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, } from './plugins/index.js';
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkHeadingIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, } 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
|
|
@@ -14,6 +14,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
14
14
|
return {
|
|
15
15
|
remarkPlugins: [
|
|
16
16
|
[remarkMdxInjectSnippets, data.snippetTreeMap],
|
|
17
|
+
remarkHeadingIds,
|
|
17
18
|
[remarkExtractTableOfContents, mdxExtracts], // modifies tree so cannot be excluded
|
|
18
19
|
[remarkExtractChangelogFilters, mdxExtracts],
|
|
19
20
|
remarkMdxRemoveUnusedVariables,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { slugifyWithCounter } from '@sindresorhus/slugify';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
import { createMdxJsxAttribute, getUnicodeId } from '../../lib/remark-utils.js';
|
|
4
|
+
import { getTOCTitle } from '../../lib/remark-utils.js';
|
|
5
|
+
export const remarkHeadingIds = () => (tree) => {
|
|
6
|
+
const slugify = slugifyWithCounter();
|
|
7
|
+
visit(tree, 'heading', (node) => {
|
|
8
|
+
if ([1, 2, 3, 4].includes(node.depth)) {
|
|
9
|
+
const title = getTOCTitle(node);
|
|
10
|
+
const encodedTitle = getUnicodeId(title);
|
|
11
|
+
let slug;
|
|
12
|
+
// if encoded title is already percent-encoded, return it as is
|
|
13
|
+
// slugify doesn't support percent-encoded characters, like Chinese, Korean, etc.
|
|
14
|
+
if (/%[0-9A-F]{2}/.test(encodedTitle)) {
|
|
15
|
+
slug = slugify(encodedTitle, {
|
|
16
|
+
decamelize: false,
|
|
17
|
+
preserveCharacters: ['%'],
|
|
18
|
+
lowercase: false,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
slug = slugify(encodedTitle, { decamelize: false });
|
|
23
|
+
}
|
|
24
|
+
const mdxJsxAttributes = [
|
|
25
|
+
createMdxJsxAttribute('level', node.depth),
|
|
26
|
+
createMdxJsxAttribute('id', slug),
|
|
27
|
+
];
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
node.attributes = mdxJsxAttributes;
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
+
node.type = 'mdxJsxFlowElement';
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
node.name = 'Heading';
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|