support for data-markdown (#15)

This commit is contained in:
Hakim El Hattab
2012-07-31 01:13:33 -04:00
parent dc05ce1575
commit 19852772fe
4 changed files with 1379 additions and 5 deletions

19
lib/js/data-markdown.js Normal file
View File

@ -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;
});
}());

1341
lib/js/showdown.js Normal file

File diff suppressed because it is too large Load Diff