Hakim El Hattab
12 years ago
4 changed files with 19 additions and 13 deletions
@ -1,18 +1,24 @@ |
|||||
// From https://gist.github.com/1343518, modified to not load showdown
|
// From https://gist.github.com/1343518
|
||||
|
// Modified by Hakim to handle markdown indented with tabs
|
||||
(function(){ |
(function(){ |
||||
|
|
||||
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){ |
[].forEach.call( document.querySelectorAll('[data-markdown]'), function fn(elem){ |
||||
|
|
||||
// strip leading whitespace so it isn't evaluated as code
|
// strip leading whitespace so it isn't evaluated as code
|
||||
var text = elem.innerHTML.replace(/\n\s*\n/g,'\n'), |
var text = elem.innerHTML; |
||||
// set indentation level so your markdown can be indented within your HTML
|
|
||||
leadingws = text.match(/^\n?(\s*)/)[1].length, |
var leadingWs = text.match(/^\n?(\s*)/)[1].length, |
||||
regex = new RegExp('\\n?\\s{' + leadingws + '}','g'), |
leadingTabs = text.match(/^\n?(\t*)/)[1].length; |
||||
md = text.replace(regex,'\n'), |
|
||||
html = (new Showdown.converter()).makeHtml(md); |
if( leadingTabs > 0 ) { |
||||
|
text = text.replace( new RegExp('\\n?\\t{' + leadingTabs + '}','g'), '\n' ); |
||||
|
} |
||||
|
else if( leadingWs > 1 ) { |
||||
|
text = text.replace( new RegExp('\\n? {' + leadingWs + '}','g'), '\n' ); |
||||
|
} |
||||
|
|
||||
// here, have sum HTML
|
// here, have sum HTML
|
||||
elem.innerHTML = html; |
elem.innerHTML = (new Showdown.converter()).makeHtml(text); |
||||
|
|
||||
}); |
}); |
||||
|
|
||||
|
Loading…
Reference in new issue