data-markdown.js 677 B

12345678910111213141516171819
  1. // From https://gist.github.com/1343518, modified to not load showdown
  2. (function(){
  3. [].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
  4. // strip leading whitespace so it isn't evaluated as code
  5. var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
  6. // set indentation level so your markdown can be indented within your HTML
  7. leadingws = text.match(/^\n?(\s*)/)[1].length,
  8. regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
  9. md = text.replace(regex,'\n'),
  10. html = (new Showdown.converter()).makeHtml(md);
  11. // here, have sum HTML
  12. elem.innerHTML = html;
  13. });
  14. })();