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

27 lines
862 B
JavaScript
Raw Normal View History

// 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
2012-08-04 03:49:29 +02:00
var slides = document.querySelectorAll('[data-markdown]');
2012-08-04 03:49:29 +02:00
for( var i = 0, len = slides.length; i < len; i++ ) {
var elem = slides[i];
// strip leading whitespace so it isn't evaluated as code
var text = elem.innerHTML;
2012-07-31 07:13:33 +02:00
2012-08-04 03:49:29 +02:00
var leadingWs = text.match(/^\n?(\s*)/)[1].length,
leadingTabs = text.match(/^\n?(\t*)/)[1].length;
2012-07-31 07:13:33 +02:00
2012-08-04 03:49:29 +02:00
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
elem.innerHTML = (new Showdown.converter()).makeHtml(text);
}
2012-07-31 07:13:33 +02:00
2012-07-31 17:44:37 +02:00
})();