2012-08-01 05:47:09 +02:00
|
|
|
// From https://gist.github.com/1343518
|
2012-09-28 15:28:06 +02:00
|
|
|
// 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-10-28 23:09:54 +01:00
|
|
|
if( typeof Showdown === 'undefined' ) {
|
|
|
|
throw 'The reveal.js Markdown plugin requires Showdown to be loaded';
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:15:36 +02:00
|
|
|
var sections = document.querySelectorAll( '[data-markdown]' );
|
2012-08-01 05:47:09 +02:00
|
|
|
|
2012-10-08 15:15:36 +02:00
|
|
|
for( var i = 0, len = sections.length; i < len; i++ ) {
|
|
|
|
var section = sections[i];
|
2012-11-16 15:25:26 +01:00
|
|
|
var notes = section.querySelector( 'aside.notes' );
|
2012-10-08 15:15:36 +02:00
|
|
|
|
|
|
|
var template = section.querySelector( 'script' );
|
2012-08-04 03:49:29 +02:00
|
|
|
|
|
|
|
// strip leading whitespace so it isn't evaluated as code
|
2012-10-08 15:15:36 +02:00
|
|
|
var text = ( template || section ).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' );
|
|
|
|
}
|
|
|
|
|
2012-10-08 15:15:36 +02:00
|
|
|
section.innerHTML = (new Showdown.converter()).makeHtml(text);
|
2012-11-16 15:25:26 +01:00
|
|
|
|
2012-11-16 15:29:25 +01:00
|
|
|
if( notes ) {
|
|
|
|
section.appendChild( notes );
|
|
|
|
}
|
2012-08-04 03:49:29 +02:00
|
|
|
}
|
2012-07-31 07:13:33 +02:00
|
|
|
|
2012-07-31 17:44:37 +02:00
|
|
|
})();
|