-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
After review, deleted swizzled components and reswizzled MDXComponent…
…s with current Docusaurus version (v3.1.0) as context. The pre.js file is now updated to the proper structure and codeblocks display correctly by default. Signed-off-by: Sunil Singh <[email protected]>
- Loading branch information
1 parent
6ba468b
commit 060b7ac
Showing
7 changed files
with
47 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,20 @@ | ||
import React, {isValidElement} from 'react'; | ||
import React from 'react'; | ||
import CodeBlock from '@theme/CodeBlock'; | ||
import CodeInline from '@theme/CodeInline'; | ||
function shouldBeInline(props) { | ||
return ( | ||
// empty code blocks have no props.children, | ||
// see https://github.com/facebook/docusaurus/pull/9704 | ||
typeof props.children !== 'undefined' && | ||
React.Children.toArray(props.children).every( | ||
(el) => typeof el === 'string' && !el.includes('\n'), | ||
) | ||
); | ||
} | ||
export default function MDXCode(props) { | ||
const inlineElements = [ | ||
'a', | ||
'abbr', | ||
'b', | ||
'br', | ||
'button', | ||
'cite', | ||
'code', | ||
'del', | ||
'dfn', | ||
'em', | ||
'i', | ||
'img', | ||
'input', | ||
'ins', | ||
'kbd', | ||
'label', | ||
'object', | ||
'output', | ||
'q', | ||
'ruby', | ||
's', | ||
'small', | ||
'span', | ||
'strong', | ||
'sub', | ||
'sup', | ||
'time', | ||
'u', | ||
'var', | ||
'wbr', | ||
]; | ||
const shouldBeInline = React.Children.toArray(props.children).every( | ||
(el) => | ||
(typeof el === 'string' && !el.includes('\n')) || | ||
(isValidElement(el) && inlineElements.includes(el.props?.mdxType)), | ||
return shouldBeInline(props) ? ( | ||
<CodeInline {...props} /> | ||
) : ( | ||
<CodeBlock {...props} /> | ||
); | ||
return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react'; | ||
import clsx from 'clsx'; | ||
import styles from './styles.module.css'; | ||
function transformImgClassName(className) { | ||
return clsx(className, styles.img); | ||
} | ||
export default function MDXImg(props) { | ||
return ( | ||
// eslint-disable-next-line jsx-a11y/alt-text | ||
<img | ||
loading="lazy" | ||
{...props} | ||
className={transformImgClassName(props.className)} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.img { | ||
height: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import React from 'react'; | ||
export default function MDXPre(props) { | ||
// With MDX 2, this element is only used for fenced code blocks | ||
// It always receives a MDXComponents/Code as children | ||
return <>{props.children}</>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters