-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (45 loc) · 1.25 KB
/
script.js
File metadata and controls
61 lines (45 loc) · 1.25 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
const sampleMarkdown = `# Markdown Previewer
Write Markdown on the left and watch the preview update in real time.
## Features
- Live rendering as you type
- Clean split-screen layout
- GitHub Pages friendly static app
### Formatting examples
**Bold text**, *italic text*, and ~~strikethrough~~ all work.
> Blockquotes help call out important notes.
1. Ordered list item
2. Another item
3. Final item
- Unordered list item
- Another bullet
| Syntax | Description |
| --- | --- |
| Header | Title |
| Paragraph | Text |
## Code block
\`\`\`js
const message = "Hello, Markdown!";
console.log(message);
\`\`\`
Visit [GitHub Pages](https://pages.github.com/) to host static apps like this.`;
const editor = document.querySelector('#editor');
const preview = document.querySelector('#preview');
const resetButton = document.querySelector('#reset-button');
marked.setOptions({
breaks: true,
gfm: true,
headerIds: false,
mangle: false
});
function renderMarkdown() {
const raw = editor.value;
preview.innerHTML = marked.parse(raw);
}
editor.value = sampleMarkdown;
renderMarkdown();
editor.addEventListener('input', renderMarkdown);
resetButton.addEventListener('click', () => {
editor.value = sampleMarkdown;
renderMarkdown();
editor.focus();
});