Dustin Schau
6 years ago
6 changed files with 70 additions and 91 deletions
@ -1,36 +0,0 @@ |
|||
/** |
|||
* Copyright (c) 2013-present, Facebook, Inc. |
|||
* |
|||
* @emails react-core |
|||
*/ |
|||
|
|||
import CodeEditor from '../components/CodeEditor'; |
|||
import React from 'react'; |
|||
import ReactDOM from 'react-dom'; |
|||
|
|||
// TODO This is a huge hack.
|
|||
// Remark transform this template to split code examples and their targets apart.
|
|||
const mountCodeExample = (containerId, code) => { |
|||
const container = document.getElementById(containerId); |
|||
const parent = container.parentElement; |
|||
|
|||
const children = Array.prototype.filter.call( |
|||
parent.children, |
|||
child => child !== container, |
|||
); |
|||
children.forEach(child => parent.removeChild(child)); |
|||
|
|||
const description = children |
|||
.map(child => child.outerHTML) |
|||
.join('') |
|||
.replace(/`([^`]+)`/g, '<code>$1</code>'); |
|||
|
|||
ReactDOM.render( |
|||
<CodeEditor code={code}> |
|||
{<div dangerouslySetInnerHTML={{__html: description}} />} |
|||
</CodeEditor>, |
|||
container, |
|||
); |
|||
}; |
|||
|
|||
export default mountCodeExample; |
Loading…
Reference in new issue