fa23-si/plugin/markdown/markdown.js

37 lines
1.2 KiB
JavaScript
Raw Normal View History

// From https://gist.github.com/1343518
2012-09-28 13:28:06 +00:00
// Modified by Hakim to handle Markdown indented with tabs
2012-07-31 15:44:37 +00:00
(function(){
2012-07-31 05:13:33 +00:00
if( typeof Showdown === 'undefined' ) {
throw 'The reveal.js Markdown plugin requires Showdown to be loaded';
}
var sections = document.querySelectorAll( '[data-markdown]' );
for( var i = 0, len = sections.length; i < len; i++ ) {
var section = sections[i];
var notes = section.querySelector( 'aside.notes' );
var template = section.querySelector( 'script' );
2012-08-04 01:49:29 +00:00
// strip leading whitespace so it isn't evaluated as code
var text = ( template || section ).innerHTML;
2012-07-31 05:13:33 +00:00
2012-08-04 01:49:29 +00:00
var leadingWs = text.match(/^\n?(\s*)/)[1].length,
leadingTabs = text.match(/^\n?(\t*)/)[1].length;
2012-07-31 05:13:33 +00:00
2012-08-04 01:49:29 +00: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' );
}
section.innerHTML = (new Showdown.converter()).makeHtml(text);
if( notes ) {
section.appendChild( notes );
}
2012-08-04 01:49:29 +00:00
}
2012-07-31 05:13:33 +00:00
2012-07-31 15:44:37 +00:00
})();