mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-23 19:48:54 +02:00
fix(v2): allow using pre tag in Markdown directly (#4428)
This commit is contained in:
parent
07ec381426
commit
ae1547c5c8
2 changed files with 20 additions and 3 deletions
|
@ -5,9 +5,9 @@
|
||||||
* LICENSE file in the root directory of this source tree.
|
* LICENSE file in the root directory of this source tree.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import React from 'react';
|
import React, {isValidElement} from 'react';
|
||||||
import Link from '@docusaurus/Link';
|
import Link from '@docusaurus/Link';
|
||||||
import CodeBlock from '@theme/CodeBlock';
|
import CodeBlock, {Props} from '@theme/CodeBlock';
|
||||||
import Heading from '@theme/Heading';
|
import Heading from '@theme/Heading';
|
||||||
import type {MDXComponentsObject} from '@theme/MDXComponents';
|
import type {MDXComponentsObject} from '@theme/MDXComponents';
|
||||||
|
|
||||||
|
@ -25,7 +25,13 @@ const MDXComponents: MDXComponentsObject = {
|
||||||
a: (props) => <Link {...props} />,
|
a: (props) => <Link {...props} />,
|
||||||
pre: (props: any) => {
|
pre: (props: any) => {
|
||||||
const {children} = props;
|
const {children} = props;
|
||||||
return <CodeBlock {...children?.props} />;
|
return (
|
||||||
|
<CodeBlock
|
||||||
|
{...((isValidElement(children)
|
||||||
|
? children?.props
|
||||||
|
: {children}) as Props)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
},
|
},
|
||||||
h1: Heading('h1'),
|
h1: Heading('h1'),
|
||||||
h2: Heading('h2'),
|
h2: Heading('h2'),
|
||||||
|
|
|
@ -188,4 +188,15 @@ function Clock(props) {
|
||||||
|
|
||||||
<code>test</code>
|
<code>test</code>
|
||||||
|
|
||||||
|
## direct using of `pre`
|
||||||
|
|
||||||
|
<pre>test</pre>
|
||||||
|
|
||||||
|
<!-- Multi-line text inside `pre` will turn into one-liner, but it's okay (https://github.com/mdx-js/mdx/issues/1095) -->
|
||||||
|
<pre>
|
||||||
|
1
|
||||||
|
2
|
||||||
|
3
|
||||||
|
</pre>
|
||||||
|
|
||||||
## Custom heading id {#custom}
|
## Custom heading id {#custom}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue