-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
85 lines (65 loc) · 2.01 KB
/
index.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
marked.setOptions({
breaks: true
})
const initialState = `# Welcome to my React Markdown Previewer!
## This is a sub-heading...
### And here's some other cool stuff:
Heres some code, \`<div></div>\`, between 2 backticks.
\`\`\`
// this is multi-line code:
function anotherExample(firstLine, lastLine) {
if (firstLine == '\`\`\`' && lastLine == '\`\`\`') {
return multiLineCode;
}
}
\`\`\`
You can also make text **bold**... whoa!
Or _italic_.
Or... wait for it... **_both!_**
And feel free to go crazy ~~crossing stuff out~~.
There's also [links](https://www.freecodecamp.org), and
> Block Quotes!
And if you want to get really crazy, even tables:
Wild Header | Crazy Header | Another Header?
------------ | ------------- | -------------
Your content can | be here, and it | can be here....
And here. | Okay. | I think we get it.
- And of course there are lists.
- Some are bulleted.
- With different indentation levels.
- That look like this.
1. And there are numbered lists too.
1. Use just 1s if you want!
1. And last but not least, let's not forget embedded images:
![freeCodeCamp Logo](https://cdn.freecodecamp.org/testable-projects-fcc/images/fcc_secondary.svg)
`;
const renderer = new marked.Renderer();
function App() {
const [text, setText] = React.useState(initialState)
return(
<div className="text-center px-4">
<h1 className="p-4">My Markdown Previewer</h1>
<textarea
name="text"
id="editor"
rows="10"
value={text}
className="textarea"
onChange={(e) => setText(e.target.value)}
></textarea>
<h3 className="mt-3">Output</h3>
<Preview markdown={text}/>
</div>
)
}
function Preview({markdown}) {
return(
<div
dangerouslySetInnerHTML={{
__html: marked(markdown, {renderer: renderer}),
}}
id="preview"
></div>
)
}
ReactDOM.render(<App/>, document.getElementById('root'));