Title / Description
Code function parseMarkdown (str) { var arr = str.split(' ') var symbols = arr[0].split('') var result = null if (symbols[0] === '#') { var count = 0 symbols.forEach(function (el) { if (el === '#') count += 1 }) if (count > 6) count = 6 result = document.createElement('h' + count) arr.shift() result.textContent = arr.join(' ') } else { result = document.createElement('p') result.textContent = arr.join(' ') } if (symbols[0] === '-' || symbols[0] === '*') { result = document.createElement('ul') li = document.createElement('li') arr.shift() li.textContent = arr.join(' ') result.appendChild(li) } document.querySelector('#result').appendChild(result) } parseMarkdown('* Hello World')
Author
Highlight as C C++ CSS Clojure Delphi ERb Groovy (beta) HAML HTML JSON Java JavaScript PHP Plain text Python Ruby SQL XML YAML diff code