mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-19 11:12:36 +02:00
fix(theme-classic): allow code tags containing inline elements to stay inline (#6767)
This commit is contained in:
parent
2e3eec2d08
commit
c1fb3deace
1 changed files with 15 additions and 1 deletions
|
@ -37,8 +37,22 @@ const MDXComponents: MDXComponentsObject = {
|
||||||
return <Head {...props}>{unwrappedChildren}</Head>;
|
return <Head {...props}>{unwrappedChildren}</Head>;
|
||||||
},
|
},
|
||||||
code: (props) => {
|
code: (props) => {
|
||||||
|
const inlineElements = [
|
||||||
|
'a',
|
||||||
|
'b',
|
||||||
|
'big',
|
||||||
|
'i',
|
||||||
|
'span',
|
||||||
|
'em',
|
||||||
|
'strong',
|
||||||
|
'sup',
|
||||||
|
'sub',
|
||||||
|
'small',
|
||||||
|
];
|
||||||
const shouldBeInline = React.Children.toArray(props.children).every(
|
const shouldBeInline = React.Children.toArray(props.children).every(
|
||||||
(el) => typeof el === 'string' && !el.includes('\n'),
|
(el) =>
|
||||||
|
(typeof el === 'string' && !el.includes('\n')) ||
|
||||||
|
(React.isValidElement(el) && inlineElements.includes(el.props.mdxType)),
|
||||||
);
|
);
|
||||||
|
|
||||||
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue