You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
894 B
39 lines
894 B
class MarkdownEditor extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.md = new Remarkable();
|
|
this.handleChange = this.handleChange.bind(this);
|
|
this.state = { value: 'Hello, **world**!' };
|
|
}
|
|
|
|
handleChange(e) {
|
|
this.setState({ value: e.target.value });
|
|
}
|
|
|
|
getRawMarkup() {
|
|
return { __html: this.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>
|
|
);
|
|
}
|
|
}
|
|
|
|
root.render(<MarkdownEditor />);
|
|
|