-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
83 lines (63 loc) · 2.16 KB
/
script.js
File metadata and controls
83 lines (63 loc) · 2.16 KB
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
const basetext = `# Welcome to my React Markdown Editor!
## 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:
`;
class App extends React.Component{
constructor(props){
super(props);
this.state = {
text: basetext,
preview: this.parseMarked(basetext)
}
}
handleValue = (ev) => {
console.log(ev.target.value);
this.setState({
text: ev.target.value,
preview: this.parseMarked(ev.target.value)
});
}
parseMarked = (val) =>{
return DOMPurify.sanitize(marked.parse(val, {breaks: true}))
}
render() {
return(<>
<Editor handleValue={this.handleValue} value={this.state.text}/>
<Previewer output={this.state.preview} />
</>);
}
};
const Editor = ({handleValue, value}) => {
return <div className={"editorWrap"}><h2 className={'title'}>Editor</h2><textarea id="editor" value={value} onChange={handleValue}/></div>
}
const Previewer = ({output}) => {
return <div className={"previewWrap"}><h2 className={'title'}>Previewer</h2><div id="preview" dangerouslySetInnerHTML={{__html: output}}></div></div>
}
ReactDOM.render(<App/>, document.querySelector('.app'));