Skip to content

Commit

Permalink
fix(v2): allow using pre tag in Markdown directly
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Mar 13, 2021
1 parent 8854020 commit a84aeb5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* 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 CodeBlock from '@theme/CodeBlock';
import CodeBlock, {Props} from '@theme/CodeBlock';
import Heading from '@theme/Heading';
import type {MDXComponentsObject} from '@theme/MDXComponents';

Expand All @@ -25,7 +25,13 @@ const MDXComponents: MDXComponentsObject = {
a: (props) => <Link {...props} />,
pre: (props: any) => {
const {children} = props;
return <CodeBlock {...children?.props} />;
return (
<CodeBlock
{...((isValidElement(children)
? children?.props
: {children}) as Props)}
/>
);
},
h1: Heading('h1'),
h2: Heading('h2'),
Expand Down
11 changes: 11 additions & 0 deletions website/src/pages/examples/markdownPageExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,15 @@ function Clock(props) {

<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}

0 comments on commit a84aeb5

Please sign in to comment.