mirror of
https://github.com/reactjs/react.dev.git
synced 2026-02-24 04:33:10 +00:00
This is still a bit opaque but it's difficult to fix with the current way CodeEditor works: - long-term CodeEditor.js could take a node reference instead of defining mountNode internally - could also use document.createElement to define the target in the code, but this could be mislead people to think this is required instead of using an existing reference see #1017, #1018, #1019
41 lines
960 B
JavaScript
41 lines
960 B
JavaScript
class MarkdownEditor extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.handleChange = this.handleChange.bind(this);
|
|
this.state = { value: 'Hello, **world**!' };
|
|
}
|
|
|
|
handleChange(e) {
|
|
this.setState({ value: e.target.value });
|
|
}
|
|
|
|
getRawMarkup() {
|
|
const md = new Remarkable();
|
|
return { __html: md.render(this.state.value) };
|
|
}
|
|
|
|
render() {
|
|
return (
|
|
<div className="MarkdownEditor">
|
|
<h3>Input</h3>
|
|
<label htmlFor="markdown-content">
|
|
Enter some markdown
|
|
</label>
|
|
<textarea
|
|
id="markdown-content"
|
|
onChange={this.handleChange}
|
|
defaultValue={this.state.value}
|
|
/>
|
|
<h3>Output</h3>
|
|
<div
|
|
className="content"
|
|
dangerouslySetInnerHTML={this.getRawMarkup()}
|
|
/>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
|
|
// let mountNode = document.querySelector('#markdown')
|
|
|
|
ReactDOM.render(<MarkdownEditor />, mountNode); |