@mintlify/common 1.0.316 → 1.0.318
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/rehype/index.d.ts +1 -0
- package/dist/mdx/plugins/rehype/index.js +1 -0
- package/dist/mdx/plugins/rehype/rehypeDynamicTailwindCss.d.ts +3 -0
- package/dist/mdx/plugins/rehype/rehypeDynamicTailwindCss.js +36 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { rehypeCodeBlocks, 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, 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
|
|
@@ -30,6 +30,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
30
30
|
rehypeRawComponents,
|
|
31
31
|
rehypeZoomImages,
|
|
32
32
|
rehypeUnicodeIds,
|
|
33
|
+
rehypeDynamicTailwindCss,
|
|
33
34
|
...rehypePlugins,
|
|
34
35
|
],
|
|
35
36
|
format: 'mdx',
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
export const MINTLIFY_TAILWIND_PREFIX = 'mint-';
|
|
3
|
+
export const rehypeDynamicTailwindCss = () => {
|
|
4
|
+
return (tree) => {
|
|
5
|
+
visit(tree, (node) => {
|
|
6
|
+
if ((node.type === 'mdxJsxFlowElement' || node.type === 'mdxJsxTextElement') &&
|
|
7
|
+
node.name &&
|
|
8
|
+
typeof node.name === 'string' &&
|
|
9
|
+
/^[a-z]/.test(node.name) && // check for valid html tags
|
|
10
|
+
!node.name.includes('.') &&
|
|
11
|
+
node.attributes.length > 0) {
|
|
12
|
+
const className = node.attributes.find((attr) => attr.type === 'mdxJsxAttribute' && attr.name === 'className');
|
|
13
|
+
if (className && typeof className.value === 'string') {
|
|
14
|
+
className.value = transformClassNames(className.value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
const transformClassNames = (value) => {
|
|
21
|
+
return value
|
|
22
|
+
.split(/\s+/)
|
|
23
|
+
.map((className) => {
|
|
24
|
+
if (!className)
|
|
25
|
+
return '';
|
|
26
|
+
if (className.startsWith('[') || className.startsWith(MINTLIFY_TAILWIND_PREFIX)) {
|
|
27
|
+
return className;
|
|
28
|
+
}
|
|
29
|
+
const parts = className.split(':');
|
|
30
|
+
const baseClass = parts.pop();
|
|
31
|
+
const variants = parts;
|
|
32
|
+
const transformedClass = `${MINTLIFY_TAILWIND_PREFIX}${baseClass}`;
|
|
33
|
+
return [...variants, transformedClass].join(':');
|
|
34
|
+
})
|
|
35
|
+
.join(' ');
|
|
36
|
+
};
|