Skip to content

Instantly share code, notes, and snippets.

@jjsub
Created October 17, 2019 17:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjsub/a9f84390c80618fa03d8c31f70534a5b to your computer and use it in GitHub Desktop.
Save jjsub/a9f84390c80618fa03d8c31f70534a5b to your computer and use it in GitHub Desktop.
// Here is how the react compenent is append to the html element in the app
// ReactDOM.render(
// <MarkdownEditor />,
// document.getElementById('markdown-example')
// );
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>
);
}
}
ReactDOM.render(
<MarkdownEditor />,
document.getElementById('markdown-example')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment