2012-08-01 05:47:09 +02:00
|
|
|
// From https://gist.github.com/1343518
|
|
|
|
// Modified by Hakim to handle markdown indented with tabs
|
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
|
2012-08-01 05:47:09 +02:00
|
|
|
var text = elem.innerHTML;
|
|
|
|
|
|
|
|
var leadingWs = text.match(/^\n?(\s*)/)[1].length,
|
|
|
|
leadingTabs = text.match(/^\n?(\t*)/)[1].length;
|
|
|
|
|
|
|
|
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' );
|
|
|
|
}
|
2012-07-31 07:13:33 +02:00
|
|
|
|
|
|
|
// here, have sum HTML
|
2012-08-01 05:47:09 +02:00
|
|
|
elem.innerHTML = (new Showdown.converter()).makeHtml(text);
|
2012-07-31 07:13:33 +02:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-07-31 17:44:37 +02:00
|
|
|
})();
|