@mintlify/common 1.0.1099 → 1.0.1101
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/remark-mdx-style-string-to-object.d.ts +2 -0
- package/dist/mdx/plugins/remark/remark-mdx-style-string-to-object.js +60 -0
- package/dist/parse-inline-style.d.ts +5 -0
- package/dist/parse-inline-style.js +33 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +7 -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, remarkMapExplicitAnchors, } from './plugins/index.js';
|
|
1
|
+
import { rehypeCodeBlocks, rehypeDynamicTailwindCss, rehypeKeyboardSymbols, rehypeListItemText, rehypeMdxExtractEndpoint, rehypeMdxExtractExamples, rehypeParamFieldIds, rehypeRawComponents, rehypeTable, rehypeUnicodeIds, rehypeZoomImages, remarkExtractChangelogFilters, remarkExtractTableOfContents, remarkFileTree, remarkFrames, remarkComponentIds, remarkMdxInjectSnippets, remarkMdxStyleStringToObject, 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
|
import { remarkNoCopyLanguage } from './plugins/remark/remarkNoCopyLanguage.js';
|
|
@@ -15,6 +15,7 @@ export const getMDXOptions = ({ data, remarkPlugins = [], rehypePlugins = [], md
|
|
|
15
15
|
return {
|
|
16
16
|
remarkPlugins: [
|
|
17
17
|
[remarkMdxInjectSnippets, data.snippetTreeMap],
|
|
18
|
+
remarkMdxStyleStringToObject,
|
|
18
19
|
[remarkResolveRelativeLinks, { path: data.path }],
|
|
19
20
|
remarkPrompt,
|
|
20
21
|
[remarkComponentIds, data.pageMetadata],
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
import { parseInlineStyle } from '../../../parse-inline-style.js';
|
|
3
|
+
const createStyleExpression = (style) => {
|
|
4
|
+
const properties = Object.entries(style).map(([property, value]) => ({
|
|
5
|
+
type: 'Property',
|
|
6
|
+
key: {
|
|
7
|
+
type: 'Literal',
|
|
8
|
+
value: property,
|
|
9
|
+
raw: JSON.stringify(property),
|
|
10
|
+
},
|
|
11
|
+
value: {
|
|
12
|
+
type: 'Literal',
|
|
13
|
+
value,
|
|
14
|
+
raw: JSON.stringify(value),
|
|
15
|
+
},
|
|
16
|
+
kind: 'init',
|
|
17
|
+
method: false,
|
|
18
|
+
shorthand: false,
|
|
19
|
+
computed: false,
|
|
20
|
+
}));
|
|
21
|
+
const estree = {
|
|
22
|
+
type: 'Program',
|
|
23
|
+
body: [
|
|
24
|
+
{
|
|
25
|
+
type: 'ExpressionStatement',
|
|
26
|
+
expression: {
|
|
27
|
+
type: 'ObjectExpression',
|
|
28
|
+
properties,
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
sourceType: 'module',
|
|
33
|
+
comments: [],
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
type: 'mdxJsxAttributeValueExpression',
|
|
37
|
+
value: JSON.stringify(style),
|
|
38
|
+
data: { estree },
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
export const remarkMdxStyleStringToObject = () => (tree) => {
|
|
42
|
+
visit(tree, (node) => {
|
|
43
|
+
var _a;
|
|
44
|
+
if (node.type !== 'mdxJsxFlowElement' && node.type !== 'mdxJsxTextElement')
|
|
45
|
+
return;
|
|
46
|
+
const firstCharacter = (_a = node.name) === null || _a === void 0 ? void 0 : _a[0];
|
|
47
|
+
if (!node.name || !firstCharacter || node.name.includes('.'))
|
|
48
|
+
return;
|
|
49
|
+
if (firstCharacter !== firstCharacter.toLowerCase())
|
|
50
|
+
return;
|
|
51
|
+
for (const attribute of node.attributes) {
|
|
52
|
+
if (attribute.type !== 'mdxJsxAttribute' ||
|
|
53
|
+
attribute.name !== 'style' ||
|
|
54
|
+
typeof attribute.value !== 'string') {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
attribute.value = createStyleExpression(parseInlineStyle(attribute.value));
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import postcss from 'postcss';
|
|
2
|
+
const CUSTOM_PROPERTY_PATTERN = /^--[a-zA-Z0-9_-]+$/;
|
|
3
|
+
const HYPHEN_PATTERN = /-([a-z])/g;
|
|
4
|
+
const MS_VENDOR_PREFIX_PATTERN = /^-ms-/;
|
|
5
|
+
const toReactStyleProperty = (property) => {
|
|
6
|
+
if (CUSTOM_PROPERTY_PATTERN.test(property))
|
|
7
|
+
return property;
|
|
8
|
+
if (!property.includes('-'))
|
|
9
|
+
return property.toLowerCase();
|
|
10
|
+
return property
|
|
11
|
+
.toLowerCase()
|
|
12
|
+
.replace(MS_VENDOR_PREFIX_PATTERN, 'ms-')
|
|
13
|
+
.replace(HYPHEN_PATTERN, (_match, character) => character.toUpperCase());
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Converts an HTML style attribute into the object shape required by React.
|
|
17
|
+
* Invalid declaration lists are treated as empty so authored HTML cannot crash rendering.
|
|
18
|
+
*/
|
|
19
|
+
export const parseInlineStyle = (style) => {
|
|
20
|
+
try {
|
|
21
|
+
const parsed = {};
|
|
22
|
+
for (const declaration of postcss.parse(style, { from: undefined }).nodes) {
|
|
23
|
+
if (declaration.type !== 'decl' || !declaration.value)
|
|
24
|
+
continue;
|
|
25
|
+
// PostCSS stores priority separately because React style objects only accept the value.
|
|
26
|
+
parsed[toReactStyleProperty(declaration.prop)] = declaration.value;
|
|
27
|
+
}
|
|
28
|
+
return parsed;
|
|
29
|
+
}
|
|
30
|
+
catch (_a) {
|
|
31
|
+
return {};
|
|
32
|
+
}
|
|
33
|
+
};
|