-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.jsx
69 lines (56 loc) · 1.39 KB
/
app.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// app.jsx
const initialMarkdown = `# Welcome to my Markdown Previewer!
## This is a sub-heading...
[Visit FreeCodeCamp](https://www.freecodecamp.org)
Here's some inline code: \`<div></div>\`
\`\`\`
// This is a code block:
function example() {
return "Hello, World!";
}
\`\`\`
- This is a list item
> This is a blockquote
![FreeCodeCamp Logo](https://cdn.freecodecamp.org/testable-projects-fcc/images/fcc_secondary.svg)
**This text is bold**
`;
marked.setOptions({
breaks: true,
gfm: true,
});
class MarkdownPreviewer extends React.Component {
constructor(props) {
super(props);
this.state = {
markdown: initialMarkdown
};
}
handleChange = (e) => {
this.setState({
markdown: e.target.value
});
}
render() {
return (
<div className="container">
<h1 className="title">Markdown Previewer</h1>
<div className="editor-container">
<h2>Editor</h2>
<textarea
id="editor"
value={this.state.markdown}
onChange={this.handleChange}
></textarea>
</div>
<div className="preview-container">
<h2>Preview</h2>
<div
id="preview"
dangerouslySetInnerHTML={{__html: marked(this.state.markdown)}}
></div>
</div>
</div>
);
}
}
ReactDOM.render(<MarkdownPreviewer />, document.getElementById('app'));