git ssb

6+

cel / downmark



Tree: d2da1e4a240525d0319f9bedceffc570047b41bc

Files: d2da1e4a240525d0319f9bedceffc570047b41bc / index.js

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

Built with git-ssb-web