git ssb

6+

cel / downmark



Tree: a6da62055a73bcc0ca4d0d94052c6cef7193d73e

Files: a6da62055a73bcc0ca4d0d94052c6cef7193d73e / index.js

1056 bytesRaw
1var toMarkdown = require('to-markdown')
2
3function debounce(fn, wait) {
4 var timeout
5 return function() {
6 clearTimeout(timeout)
7 timeout = setTimeout(fn, wait)
8 }
9}
10
11var value
12var inputEl = document.getElementById('input')
13var outputEl = document.getElementById('output')
14var outputText = outputEl.appendChild(document.createTextNode(''))
15var opt = {
16 gfm: true,
17 converters: [{
18 filter: ['span', 'div', 'small', 'font'],
19 replacement: function (content) {
20 return content
21 }
22 },
23 {
24 filter: 'li',
25 replacement: function (content, node) {
26 content = content.replace(/^\s+/, '').replace(/\n/gm, '\n ')
27 var parent = node.parentNode
28 var index = Array.prototype.indexOf.call(parent.children, node) + 1
29
30 var prefix = /ol/i.test(parent.nodeName) ? index + '. ' : '- '
31 return prefix + content
32 }
33 }]
34}
35
36inputEl.onkeydown = inputEl.onkeyup = debounce(function() {
37 var newVal = inputEl.innerHTML
38 if (value == newVal) return
39 value = newVal
40 outputText.nodeValue = toMarkdown(value, opt)
41})
42

Built with git-ssb-web