1
0
Fork 0
why-cant-we-deploy-today/lib/js/data-markdown.js

19 lines
677 B
JavaScript
Raw Normal View History

2012-07-31 07:13:33 +02:00
// From https://gist.github.com/1343518, modified to not load showdown
2012-07-31 17:44:37 +02:00
(function(){
2012-07-31 07:13:33 +02:00
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){
2012-07-31 17:44:37 +02:00
2012-07-31 07:13:33 +02:00
// strip leading whitespace so it isn't evaluated as code
var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'),
// set indentation level so your markdown can be indented within your HTML
leadingws = text.match(/^\n?(\s*)/)[1].length,
regex = new RegExp('\\n?\\s{' + leadingws + '}','g'),
md = text.replace(regex,'\n'),
html = (new Showdown.converter()).makeHtml(md);
// here, have sum HTML
elem.innerHTML = html;
});
2012-07-31 17:44:37 +02:00
})();