@mintlify/common 1.0.1020 → 1.0.1021
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/remarkPrompt.js +6 -4
- package/dist/mdx/plugins/remark/remarkUnwrapInlineJsx.d.ts +11 -0
- package/dist/mdx/plugins/remark/remarkUnwrapInlineJsx.js +26 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -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, 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, } 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
|
remarkPrompt,
|
|
19
19
|
[remarkComponentIds, data.pageMetadata],
|
|
20
20
|
remarkUnwrapJsxHeadings,
|
|
21
|
+
remarkUnwrapInlineJsx,
|
|
21
22
|
[remarkExtractTableOfContents, mdxExtracts, data.pageMetadata], // modifies tree so cannot be excluded
|
|
22
23
|
[remarkExtractChangelogFilters, mdxExtracts],
|
|
23
24
|
[remarkMdxExtractPanel, mdxExtracts],
|
|
@@ -20,5 +20,6 @@ export * from './remarkVideo.js';
|
|
|
20
20
|
export * from './remarkExtractMultiView.js';
|
|
21
21
|
export * from './remarkPrompt.js';
|
|
22
22
|
export * from './remarkResolveRelativeLinks.js';
|
|
23
|
+
export * from './remarkUnwrapInlineJsx.js';
|
|
23
24
|
export * from './remarkUnwrapJsxHeadings.js';
|
|
24
25
|
export * from './remarkVisibilityForMarkdown.js';
|
|
@@ -20,5 +20,6 @@ export * from './remarkVideo.js';
|
|
|
20
20
|
export * from './remarkExtractMultiView.js';
|
|
21
21
|
export * from './remarkPrompt.js';
|
|
22
22
|
export * from './remarkResolveRelativeLinks.js';
|
|
23
|
+
export * from './remarkUnwrapInlineJsx.js';
|
|
23
24
|
export * from './remarkUnwrapJsxHeadings.js';
|
|
24
25
|
export * from './remarkVisibilityForMarkdown.js';
|
|
@@ -12,7 +12,7 @@ const dedent = (text) => {
|
|
|
12
12
|
export const remarkPrompt = () => {
|
|
13
13
|
return (tree, file) => {
|
|
14
14
|
const source = String(file.value);
|
|
15
|
-
|
|
15
|
+
const transformPromptNode = (node) => {
|
|
16
16
|
if (node.name !== 'Prompt')
|
|
17
17
|
return;
|
|
18
18
|
if (!node.position)
|
|
@@ -23,7 +23,7 @@ export const remarkPrompt = () => {
|
|
|
23
23
|
const endOffset = node.position.end.offset;
|
|
24
24
|
if (startOffset === undefined || endOffset === undefined)
|
|
25
25
|
return;
|
|
26
|
-
const nodeSource = source.slice(startOffset, endOffset);
|
|
26
|
+
const nodeSource = source.slice(startOffset, endOffset).replace(/\r\n?/g, '\n');
|
|
27
27
|
let inString = false;
|
|
28
28
|
let braceDepth = 0;
|
|
29
29
|
let openTagEnd = -1;
|
|
@@ -34,7 +34,7 @@ export const remarkPrompt = () => {
|
|
|
34
34
|
inString = false;
|
|
35
35
|
continue;
|
|
36
36
|
}
|
|
37
|
-
if (ch === '"' || ch === "'") {
|
|
37
|
+
if (ch === '"' || ch === "'" || ch === '`') {
|
|
38
38
|
inString = ch;
|
|
39
39
|
continue;
|
|
40
40
|
}
|
|
@@ -84,6 +84,8 @@ export const remarkPrompt = () => {
|
|
|
84
84
|
},
|
|
85
85
|
});
|
|
86
86
|
node.children = [];
|
|
87
|
-
}
|
|
87
|
+
};
|
|
88
|
+
visit(tree, 'mdxJsxFlowElement', transformPromptNode);
|
|
89
|
+
visit(tree, 'mdxJsxTextElement', transformPromptNode);
|
|
88
90
|
};
|
|
89
91
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
/**
|
|
3
|
+
* Unwraps the paragraph MDX generates around the content of inline components
|
|
4
|
+
* authored in block form (`<Badge>\nBeta\n</Badge>`). Without this, the
|
|
5
|
+
* paragraph renders inside the component's inline element (`<span><p>`,
|
|
6
|
+
* `<button><p>`) — invalid HTML that browsers reparse, causing hydration
|
|
7
|
+
* mismatches. Any other block content (multiple paragraphs, headings,
|
|
8
|
+
* blockquotes, ...) is left untouched (flattening would silently merge
|
|
9
|
+
* blocks) and surfaced with a warning instead.
|
|
10
|
+
*/
|
|
11
|
+
export declare const remarkUnwrapInlineJsx: () => (tree: Root) => void;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { visit } from 'unist-util-visit';
|
|
2
|
+
const INLINE_JSX_COMPONENTS = new Set(['Badge', 'Tooltip']);
|
|
3
|
+
/**
|
|
4
|
+
* Unwraps the paragraph MDX generates around the content of inline components
|
|
5
|
+
* authored in block form (`<Badge>\nBeta\n</Badge>`). Without this, the
|
|
6
|
+
* paragraph renders inside the component's inline element (`<span><p>`,
|
|
7
|
+
* `<button><p>`) — invalid HTML that browsers reparse, causing hydration
|
|
8
|
+
* mismatches. Any other block content (multiple paragraphs, headings,
|
|
9
|
+
* blockquotes, ...) is left untouched (flattening would silently merge
|
|
10
|
+
* blocks) and surfaced with a warning instead.
|
|
11
|
+
*/
|
|
12
|
+
export const remarkUnwrapInlineJsx = () => (tree) => {
|
|
13
|
+
visit(tree, 'mdxJsxFlowElement', (node) => {
|
|
14
|
+
if (!node.name || !INLINE_JSX_COMPONENTS.has(node.name))
|
|
15
|
+
return;
|
|
16
|
+
const [onlyChild] = node.children;
|
|
17
|
+
if (node.children.length === 1 && (onlyChild === null || onlyChild === void 0 ? void 0 : onlyChild.type) === 'paragraph') {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- phrasing content is valid at runtime; mdast types only allow block content here
|
|
19
|
+
node.children = onlyChild.children;
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (node.children.length > 0) {
|
|
23
|
+
console.warn(`<${node.name}> is an inline component; block-level content inside it renders invalid HTML. Use a single line of content.`);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
};
|