@mintlify/common 1.0.592 → 1.0.593
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/remarkExtractMultiView.d.ts +3 -0
- package/dist/mdx/plugins/remark/remarkExtractMultiView.js +76 -0
- package/dist/mdx/server-only/getMdx.js +4 -0
- package/dist/mdx/utils.js +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/mdx/MdxExtracts.d.ts +2 -0
- package/dist/types/mdx/MultiViewItemType.d.ts +7 -0
- package/dist/types/mdx/MultiViewItemType.js +1 -0
- package/dist/types/mdx/index.d.ts +1 -0
- package/dist/types/mdx/index.js +1 -0
- package/package.json +2 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, } from './plugins/index.js';
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxRemoveUnusedVariables, remarkRemoveImports, remarkMdxExtractPanel, remarkVideo, remarkExtractMultiView, } 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
|
|
@@ -18,6 +18,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
18
18
|
[remarkExtractTableOfContents, mdxExtracts, data.pageMetadata], // modifies tree so cannot be excluded
|
|
19
19
|
[remarkExtractChangelogFilters, mdxExtracts],
|
|
20
20
|
[remarkMdxExtractPanel, mdxExtracts],
|
|
21
|
+
[remarkExtractMultiView, mdxExtracts],
|
|
21
22
|
remarkMdxRemoveUnusedVariables,
|
|
22
23
|
remarkFrames,
|
|
23
24
|
remarkRemoveImports,
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import remarkStringify from 'remark-stringify';
|
|
2
|
+
import { unified } from 'unified';
|
|
3
|
+
import { visit } from 'unist-util-visit';
|
|
4
|
+
import { coreRemarkMdxPlugins } from '../../remark.js';
|
|
5
|
+
export const remarkExtractMultiView = (mdxExtracts) => {
|
|
6
|
+
return (tree) => {
|
|
7
|
+
const multiViews = [];
|
|
8
|
+
const sanitizeNode = (node) => {
|
|
9
|
+
const sanitized = Object.assign({}, node);
|
|
10
|
+
if ('attributes' in sanitized && Array.isArray(sanitized.attributes)) {
|
|
11
|
+
sanitized.attributes = sanitized.attributes.map((attr) => {
|
|
12
|
+
if (attr.value != null && typeof attr.value !== 'string') {
|
|
13
|
+
return Object.assign(Object.assign({}, attr), { value: String(attr.value) });
|
|
14
|
+
}
|
|
15
|
+
return attr;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if ('children' in sanitized && Array.isArray(sanitized.children)) {
|
|
19
|
+
sanitized.children = sanitized.children.map(sanitizeNode);
|
|
20
|
+
}
|
|
21
|
+
return sanitized;
|
|
22
|
+
};
|
|
23
|
+
const stringifyNode = (node) => {
|
|
24
|
+
try {
|
|
25
|
+
return unified()
|
|
26
|
+
.use(coreRemarkMdxPlugins)
|
|
27
|
+
.use(remarkStringify)
|
|
28
|
+
.stringify(sanitizeNode(node));
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
console.error('Error converting MDX content to markdown:', error);
|
|
32
|
+
return '';
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const getStringValue = (attribute) => {
|
|
36
|
+
if (!(attribute === null || attribute === void 0 ? void 0 : attribute.value)) {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
if (typeof attribute.value === 'string') {
|
|
40
|
+
return attribute.value;
|
|
41
|
+
}
|
|
42
|
+
if (typeof attribute.value === 'object' && 'value' in attribute.value) {
|
|
43
|
+
return String(attribute.value.value);
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
48
|
+
if (node.name === 'View') {
|
|
49
|
+
const title = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'title'));
|
|
50
|
+
const icon = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'icon'));
|
|
51
|
+
const iconType = getStringValue(node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'iconType'));
|
|
52
|
+
const content = stringifyNode({
|
|
53
|
+
type: 'root',
|
|
54
|
+
children: node.children,
|
|
55
|
+
});
|
|
56
|
+
if (title) {
|
|
57
|
+
const viewItem = {
|
|
58
|
+
title,
|
|
59
|
+
content,
|
|
60
|
+
};
|
|
61
|
+
if (icon) {
|
|
62
|
+
viewItem.icon = icon;
|
|
63
|
+
}
|
|
64
|
+
if (iconType) {
|
|
65
|
+
viewItem.iconType = iconType;
|
|
66
|
+
}
|
|
67
|
+
multiViews.push(viewItem);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
if (mdxExtracts && multiViews.length) {
|
|
72
|
+
mdxExtracts.multiViewItems = multiViews;
|
|
73
|
+
}
|
|
74
|
+
return tree;
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -54,6 +54,10 @@ export function getMdx(_a) {
|
|
|
54
54
|
// so we need to restore the original mdxExtracts
|
|
55
55
|
mdxExtracts = Object.assign(Object.assign({}, originalMdxExtracts), { codeExamples: mdxExtracts.codeExamples });
|
|
56
56
|
}
|
|
57
|
+
// to avoid flash on initial load, we set the first view as active
|
|
58
|
+
if (mdxExtracts.multiViewItems) {
|
|
59
|
+
mdxExtracts.multiViewItems = mdxExtracts.multiViewItems.map((item, index) => (Object.assign(Object.assign({}, item), { active: index === 0 })));
|
|
60
|
+
}
|
|
57
61
|
return {
|
|
58
62
|
mdxExtracts,
|
|
59
63
|
mdxSource,
|