Skip to content

Commit

Permalink
fix(v2): render escaped HTML entities inside code properly
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 committed Apr 11, 2021
1 parent cb403af commit d032e4c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 22 additions & 0 deletions website/src/pages/examples/markdownPageExample.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>&#124;&#124;</code>

Code tag + double pipe: <code>||</code>

0 comments on commit d032e4c

Please sign in to comment.