@mintlify/common 1.0.1082 → 1.0.1084
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/remarkMapExplicitAnchors.d.ts +2 -0
- package/dist/mdx/plugins/remark/remarkMapExplicitAnchors.js +87 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFileTree, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkResolveRelativeLinks, remarkVideo, remarkMdxClientComponentBoundaries, remarkExtractMultiView, remarkPrompt, remarkUnwrapInlineJsx, remarkUnwrapJsxHeadings, } from './plugins/index.js';
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFileTree, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkResolveRelativeLinks, remarkVideo, remarkMdxClientComponentBoundaries, remarkExtractMultiView, remarkPrompt, remarkUnwrapInlineJsx, remarkUnwrapJsxHeadings, remarkMapExplicitAnchors, } 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
|
|
@@ -30,6 +30,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
30
30
|
remarkMermaid,
|
|
31
31
|
remarkVideo,
|
|
32
32
|
...remarkPlugins,
|
|
33
|
+
remarkMapExplicitAnchors,
|
|
33
34
|
[remarkMdxRemoveUnknownJsx, { allowlist: allowedComponents }],
|
|
34
35
|
remarkMdxClientComponentBoundaries,
|
|
35
36
|
],
|
|
@@ -23,6 +23,7 @@ export * from './remarkVideo.js';
|
|
|
23
23
|
export * from './remarkExtractMultiView.js';
|
|
24
24
|
export * from './remarkPrompt.js';
|
|
25
25
|
export * from './remarkResolveRelativeLinks.js';
|
|
26
|
+
export * from './remarkMapExplicitAnchors.js';
|
|
26
27
|
export * from './remarkUnwrapInlineJsx.js';
|
|
27
28
|
export * from './remarkUnwrapJsxHeadings.js';
|
|
28
29
|
export * from './remarkVisibilityForMarkdown.js';
|
|
@@ -23,6 +23,7 @@ export * from './remarkVideo.js';
|
|
|
23
23
|
export * from './remarkExtractMultiView.js';
|
|
24
24
|
export * from './remarkPrompt.js';
|
|
25
25
|
export * from './remarkResolveRelativeLinks.js';
|
|
26
|
+
export * from './remarkMapExplicitAnchors.js';
|
|
26
27
|
export * from './remarkUnwrapInlineJsx.js';
|
|
27
28
|
export * from './remarkUnwrapJsxHeadings.js';
|
|
28
29
|
export * from './remarkVisibilityForMarkdown.js';
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { walk } from 'estree-walker';
|
|
2
|
+
import { visit } from 'unist-util-visit';
|
|
3
|
+
// `remarkMarkAndUnravel` flags author-written JSX with `_mdxExplicitJsx`, and `recmaJsxRewrite`
|
|
4
|
+
// leaves flagged elements as intrinsics instead of resolving them through the components map.
|
|
5
|
+
// Clearing the flag for `a` keeps `<a href="/page">` equivalent to `[page](/page)`, so both render
|
|
6
|
+
// through DynamicLink and pick up client-side routing and the deployment base path.
|
|
7
|
+
const EXPLICIT_JSX_DATA_KEY = '_mdxExplicitJsx';
|
|
8
|
+
const MAPPED_TAGS = new Set(['a']);
|
|
9
|
+
const unmarkExplicitJsx = (node) => {
|
|
10
|
+
if (node.data)
|
|
11
|
+
delete node.data[EXPLICIT_JSX_DATA_KEY];
|
|
12
|
+
};
|
|
13
|
+
// Only anchors that need DynamicLink are rerouted: absolute internal hrefs (the ones that must pick
|
|
14
|
+
// up the base path) and dynamic hrefs we cannot read at compile time. Anchors with no href, a bare
|
|
15
|
+
// relative href, a hash, or an external href already render correctly as intrinsics, and routing
|
|
16
|
+
// them would hand them to DynamicLink's external branch (new tab + link styling).
|
|
17
|
+
const isAbsoluteInternalHref = (value) => value.startsWith('/') && !value.startsWith('//');
|
|
18
|
+
const unmarkJsxElement = (node) => {
|
|
19
|
+
if (!node.name || !MAPPED_TAGS.has(node.name))
|
|
20
|
+
return;
|
|
21
|
+
let hasSpread = false;
|
|
22
|
+
for (const attribute of node.attributes) {
|
|
23
|
+
if (attribute.type === 'mdxJsxExpressionAttribute') {
|
|
24
|
+
hasSpread = true;
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
if (attribute.name !== 'href')
|
|
28
|
+
continue;
|
|
29
|
+
if (typeof attribute.value === 'string') {
|
|
30
|
+
if (isAbsoluteInternalHref(attribute.value))
|
|
31
|
+
unmarkExplicitJsx(node);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (attribute.value)
|
|
35
|
+
unmarkExplicitJsx(node);
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
if (hasSpread)
|
|
39
|
+
unmarkExplicitJsx(node);
|
|
40
|
+
};
|
|
41
|
+
export const remarkMapExplicitAnchors = () => {
|
|
42
|
+
return (tree) => {
|
|
43
|
+
visit(tree, 'mdxJsxFlowElement', unmarkJsxElement);
|
|
44
|
+
visit(tree, 'mdxJsxTextElement', unmarkJsxElement);
|
|
45
|
+
// `remarkMarkAndUnravel` walks the estree of expression nodes as well as ESM, so
|
|
46
|
+
// `{items.map((i) => <a href={i.href} />)}` needs the same treatment as an exported component.
|
|
47
|
+
const unmarkEstreeAnchors = (node) => {
|
|
48
|
+
var _a;
|
|
49
|
+
const estree = (_a = node.data) === null || _a === void 0 ? void 0 : _a.estree;
|
|
50
|
+
if (!estree)
|
|
51
|
+
return;
|
|
52
|
+
walk(estree, {
|
|
53
|
+
enter(estreeNode) {
|
|
54
|
+
if (estreeNode.type !== 'JSXElement')
|
|
55
|
+
return;
|
|
56
|
+
const name = estreeNode.openingElement.name;
|
|
57
|
+
if (name.type !== 'JSXIdentifier' || !MAPPED_TAGS.has(name.name))
|
|
58
|
+
return;
|
|
59
|
+
let hasSpread = false;
|
|
60
|
+
for (const attribute of estreeNode.openingElement.attributes) {
|
|
61
|
+
if (attribute.type === 'JSXSpreadAttribute') {
|
|
62
|
+
hasSpread = true;
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
if (attribute.name.type !== 'JSXIdentifier' || attribute.name.name !== 'href')
|
|
66
|
+
continue;
|
|
67
|
+
const value = attribute.value;
|
|
68
|
+
if ((value === null || value === void 0 ? void 0 : value.type) === 'Literal') {
|
|
69
|
+
if (typeof value.value === 'string' && isAbsoluteInternalHref(value.value)) {
|
|
70
|
+
unmarkExplicitJsx(estreeNode);
|
|
71
|
+
}
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
if (value)
|
|
75
|
+
unmarkExplicitJsx(estreeNode);
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (hasSpread)
|
|
79
|
+
unmarkExplicitJsx(estreeNode);
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
visit(tree, 'mdxjsEsm', unmarkEstreeAnchors);
|
|
84
|
+
visit(tree, 'mdxFlowExpression', unmarkEstreeAnchors);
|
|
85
|
+
visit(tree, 'mdxTextExpression', unmarkEstreeAnchors);
|
|
86
|
+
};
|
|
87
|
+
};
|