mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-05 13:17:23 +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 = {
|
||||
code: (props) => {
|
||||
const {children} = props;
|
||||
if (typeof children === 'string') {
|
||||
if (!children.includes('\n')) {
|
||||
return <code {...props} />;
|
||||
}
|
||||
return <CodeBlock {...props} />;
|
||||
|
||||
// For retrocompatibility purposes (pretty rare use case)
|
||||
// See https://github.com/facebook/docusaurus/pull/1584
|
||||
if (isValidElement(children)) {
|
||||
return children;
|
||||
}
|
||||
return children;
|
||||
|
||||
return !children.includes('\n') ? (
|
||||
<code {...props} />
|
||||
) : (
|
||||
<CodeBlock {...props} />
|
||||
);
|
||||
},
|
||||
a: (props) => <Link {...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 (
|
||||
<CodeBlock
|
||||
{...((isValidElement(children)
|
||||
|
|
|
@ -200,3 +200,25 @@ function Clock(props) {
|
|||
</pre>
|
||||
|
||||
## 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