Created
July 21, 2020 14:42
-
-
Save VasVV/c1c85f879a4ad180b92ced5a19038c32 to your computer and use it in GitHub Desktop.
Markdown Previewer - React
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script> | |
| <div id='app'> | |
| </div> | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| marked.setOptions({ | |
| gfm: true, | |
| breaks: true | |
| }); | |
| class MyForm extends React.Component { | |
| constructor(props) { | |
| super(props); | |
| this.state = { input: '' }; | |
| } | |
| myChangeHandler = (event) => { | |
| this.setState({input: event.target.value}); | |
| } | |
| render() { | |
| return ( | |
| <div> | |
| <p>Input your text here:</p> | |
| <textarea id="editor" defaultValue=' > Quote # Header ## Header 2 [link to Google!](http://google.com) <br>`<code></code>` ``` if(a) {return b} ``` <br> **Bold text** <br>  * Item 1 | |
| * Item 2 ' onChange={this.myChangeHandler} > | |
| </textarea> | |
| <p> The result is here: </p> | |
| <div id="preview" dangerouslySetInnerHTML={{ __html: marked(this.state.input)}} /> | |
| </div> | |
| ); | |
| } | |
| } | |
| React.render(<MyForm />, document.getElementById('app')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.0/react.min.js"></script> | |
| <script src="https://cdnjs.cloudflare.com/ajax/libs/marked/0.8.0/marked.min.js"></script> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| body {padding: 0 50vh 0 50vh} | |
| textarea { width: 50vw; height: 25vh } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment