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
| document.addEventListener('DOMContentLoaded', (event) => { const input = document.getElementById('input'); const output = document.getElementById('output'); input.addEventListener('input', (event) => { output.innerHTML = handleinput(input.value); }); });
function handleinput(ori){ let oris = ori.split('\n'); let filter = [] for (let i of oris){ if (i){ filter = [...filter, i] } }; let title = [] for (let i of filter) { if (i[0] == '#' && /#+\s/.test(i)){ let n = i.match(/#+\s/)[0].length; console.log(i.match(/#+\s/)[0]) i = `<h${n-1}>${i.slice(n)}</h${n-1}>` } title = [...title, i] };
let rows = [] for (let i of title){ if (i){ rows = [...rows, `<p>${i}</p>`] } };
md = rows.join('\n') return md };
|