-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkdown-editor.js
36 lines (31 loc) · 1.05 KB
/
markdown-editor.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
import Remarkable from 'remarkable'
class MarkdownEditor extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
this.handleChange = this.handleChange.bind(this)
}
handleChange(e) {
this.output.innerHTML = this.getRawMarkup()
}
getRawMarkup() {
const md = new Remarkable()
return md.render(this.input.value)
}
connectedCallback() {
this.shadowRoot.innerHTML = `
<div class="MarkdownEditor">
<h3>Input</h3>
<label for="markdown-content">
Enter some markdown
</label>
<textarea id="markdown-content"></textarea>
<h3>Output</h3>
<div class="content"/>
</div>`
this.input = this.shadowRoot.querySelector('#markdown-content')
this.output = this.shadowRoot.querySelector('.content')
this.input.addEventListener('input', this.handleChange)
}
}
customElements.define('markdown-editor', MarkdownEditor)