mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-05 21:27:24 +02:00
fix(v2): render escaped HTML entities inside code properly (#4598)
This commit is contained in:
parent
7c56f816c6
commit
6b0df65786
2 changed files with 40 additions and 7 deletions
|
@ -14,17 +14,28 @@ import type {MDXComponentsObject} from '@theme/MDXComponents';
|
||||||
const MDXComponents: MDXComponentsObject = {
|
const MDXComponents: MDXComponentsObject = {
|
||||||
code: (props) => {
|
code: (props) => {
|
||||||
const {children} = props;
|
const {children} = props;
|
||||||
if (typeof children === 'string') {
|
|
||||||
if (!children.includes('\n')) {
|
// For retrocompatibility purposes (pretty rare use case)
|
||||||
return <code {...props} />;
|
// See https://github.com/facebook/docusaurus/pull/1584
|
||||||
}
|
if (isValidElement(children)) {
|
||||||
return <CodeBlock {...props} />;
|
|
||||||
}
|
|
||||||
return children;
|
return children;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !children.includes('\n') ? (
|
||||||
|
<code {...props} />
|
||||||
|
) : (
|
||||||
|
<CodeBlock {...props} />
|
||||||
|
);
|
||||||
},
|
},
|
||||||
a: (props) => <Link {...props} />,
|
a: (props) => <Link {...props} />,
|
||||||
pre: (props) => {
|
pre: (props) => {
|
||||||
const {children} = props;
|
const {children} = props as {children: any};
|
||||||
|
|
||||||
|
// See comment for `code` above
|
||||||
|
if (isValidElement(children?.props?.children)) {
|
||||||
|
return children?.props.children;
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<CodeBlock
|
<CodeBlock
|
||||||
{...((isValidElement(children)
|
{...((isValidElement(children)
|
||||||
|
|
|
@ -200,3 +200,25 @@ function Clock(props) {
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
## Custom heading id {#custom}
|
## Custom heading id {#custom}
|
||||||
|
|
||||||
|
## Children elements inside pre/code elements
|
||||||
|
|
||||||
|
See https://github.com/facebook/docusaurus/pull/1584
|
||||||
|
|
||||||
|
<pre><code>
|
||||||
|
<BrowserWindow url="http://localhost:3000" >
|
||||||
|
Lol bro
|
||||||
|
</BrowserWindow>
|
||||||
|
</code></pre>
|
||||||
|
|
||||||
|
<code>
|
||||||
|
<BrowserWindow url="http://localhost:3000" >
|
||||||
|
Lol bro
|
||||||
|
</BrowserWindow>
|
||||||
|
</code>
|
||||||
|
|
||||||
|
## Pipe
|
||||||
|
|
||||||
|
Code tag + double pipe: <code>||</code>
|
||||||
|
|
||||||
|
Code tag + double pipe: <code>||</code>
|
||||||
|
|
Loading…
Add table
Reference in a new issue