Files: 7bbb0b53aa02c9aeea1be2508f96b75d973cc6b9 / index.js
699 bytesRaw
1 | var toMarkdown = require('to-markdown') |
2 | |
3 | function debounce(fn, wait) { |
4 | var timeout |
5 | return function() { |
6 | clearTimeout(timeout) |
7 | timeout = setTimeout(fn, wait) |
8 | } |
9 | } |
10 | |
11 | var value |
12 | var inputEl = document.getElementById('input') |
13 | var outputEl = document.getElementById('output') |
14 | var outputText = outputEl.appendChild(document.createTextNode('')) |
15 | var opt = { |
16 | gfm: true, |
17 | converters: [{ |
18 | filter: ['span', 'div', 'small', 'font'], |
19 | replacement: function (content) { |
20 | return content |
21 | } |
22 | }] |
23 | } |
24 | inputEl.onkeydown = inputEl.onkeyup = debounce(function() { |
25 | var newVal = inputEl.innerHTML |
26 | if (value == newVal) return |
27 | value = newVal |
28 | outputText.nodeValue = toMarkdown(value, opt) |
29 | }) |
30 |
Built with git-ssb-web