From 19852772fe3aaa22d3447cb57b5e1b84d69814ba Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Tue, 31 Jul 2012 01:13:33 -0400 Subject: support for data-markdown (#15) --- lib/js/data-markdown.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/js/data-markdown.js (limited to 'lib/js/data-markdown.js') diff --git a/lib/js/data-markdown.js b/lib/js/data-markdown.js new file mode 100644 index 0000000..d1b27c4 --- /dev/null +++ b/lib/js/data-markdown.js @@ -0,0 +1,19 @@ +// From https://gist.github.com/1343518, modified to not load showdown +(function boom(){ + + [].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){ + + // 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; + + }); + +}()); \ No newline at end of file -- cgit v1.2.3