Skip to content

Commit

Permalink
Remove inner <code> from CodeBlocks, refs #110
Browse files Browse the repository at this point in the history
  • Loading branch information
mariuswilms committed Aug 23, 2019
1 parent 0ac1c59 commit 5c86a4e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</CodeBlock>

<CodeBlock title="Example">
<div>test</div>
<div>CodeBlock directly used component</div>
</CodeBlock>

<Playground>
Expand Down
2 changes: 0 additions & 2 deletions frontend/src/CodeBlock/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { copyTextToClipboard } from '../utils';
// We see the first case when the component is used explictly and the second,
// when it is instantiated by the DocTransformer, turning a <pre> into a
// CodeBlock.
//
// TODO: If child is <code> unwrap and turn into string.
function CodeBlock(props) {
let isEscaped = props.escaped;

Expand Down
9 changes: 8 additions & 1 deletion frontend/src/Doc/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,14 @@ function Doc(props) {
h3: props => <Heading {...props} level="gamma" docTitle={docTitle} isJumptarget={true} />,
h4: props => <Heading {...props} level="delta" docTitle={docTitle} isJumptarget={true} />,
img: props => <Image {...props} />,
pre: props => <CodeBlock escaped {...props} />,
pre: (props) => {
// When Markdown fenced code blocks get converted to <pre> they
// additionally include inner <code>. We cannot use orphans as this create
// empty "ghost" elements.
let children = props.children.replace(/^<code>/, '').replace(/<\/code>$/, '');

return <CodeBlock escaped {...props} children={children} />,
}
};

const orphans = ["p > img", "p > video"];
Expand Down

0 comments on commit 5c86a4e

Please sign in to comment.