-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
102 lines (75 loc) · 2.43 KB
/
script.js
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { marked } from "https://cdn.skypack.dev/[email protected]";
marked.setOptions({
breaks: true });
const renderer = new marked.Renderer();
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
text: example };
this.handleChange = this.handleChange.bind(this);
}
handleChange(event) {
this.setState({
text: event.target.value });
}
render() {
return /*#__PURE__*/(
React.createElement("div", null, /*#__PURE__*/
React.createElement("h1", { id: "header" }, "Markdown Previewer"), /*#__PURE__*/
React.createElement(Editor, { text: this.state.text, onChange: this.handleChange }), /*#__PURE__*/
React.createElement(Preview, { text: this.state.text })));
}}
// App ends
const Editor = props => {
return /*#__PURE__*/(
React.createElement("div", null, /*#__PURE__*/
React.createElement("h2", null, "Editor"), /*#__PURE__*/
React.createElement("textarea", {
id: "editor",
value: props.text,
onChange: props.onChange })));
}; //Editor
class Preview extends React.Component {
constructor(props) {
super(props);
}
render() {
const markdown = this.props.text;
return /*#__PURE__*/(
React.createElement("div", null, /*#__PURE__*/
React.createElement("h2", null, "Preview"), /*#__PURE__*/
React.createElement("div", {
id: "preview",
dangerouslySetInnerHTML: {
__html: marked(markdown, { renderer: renderer }) } })));
}}
//Preview
const example = `# This is an example of an H1 header.
## This is an H2 sub-header example.
**This is bold text**.
*This text is italicized*.
You can share a block quote like this:
> Don't believe everything you read on the internet, dude.
> Abraham Lincoln
Inline code is made possible by using \`backticks\`.
If you want to add a list, tha's easy too. You can make the list ordered or unordered like so:
### List
- Dogs
- Cats
- Birds
### List
1. Winner
2. Runner-up
3. Third place
A block of code is made possible by triple back ticks, and is shown below:
\`\`\`
function(arg){
return (arg + 1);
}
\`\`\`
You can even add links to your text like this: [FreeCodeCamp](www.freecodecamp.org).
Lastly, you can also include an image to spice things up.

`;
ReactDOM.render( /*#__PURE__*/React.createElement(App, null), document.getElementById('app'));