fix bug where markdown notes in last slide would not parse #574

This commit is contained in:
Hakim El Hattab 2013-08-24 16:13:24 -04:00
parent d62093c228
commit 571fb67864
1 changed files with 15 additions and 26 deletions

View File

@ -75,12 +75,12 @@
/** /**
* Helper function for constructing a markdown slide. * Helper function for constructing a markdown slide.
*/ */
function createMarkdownSlide( data ) { function createMarkdownSlide( content, options ) {
var content = data.content || data; var notesMatch = content.split( new RegExp( options.notesSeparator, 'mgi' ) );
if( data.notes ) { if( notesMatch.length === 2 ) {
content += '<aside class="notes" data-markdown>' + data.notes + '</aside>'; content = notesMatch[0] + '<aside class="notes" data-markdown>' + notesMatch[1].trim() + '</aside>';
} }
return '<script type="text/template">' + content + '</script>'; return '<script type="text/template">' + content + '</script>';
@ -99,17 +99,13 @@
options.attributes = options.attributes || ''; options.attributes = options.attributes || '';
var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ), var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ),
horizontalSeparatorRegex = new RegExp( options.separator ), horizontalSeparatorRegex = new RegExp( options.separator );
notesSeparatorRegex = new RegExp( options.notesSeparator, 'mgi' );
var matches, var matches,
noteMatch,
lastIndex = 0, lastIndex = 0,
isHorizontal, isHorizontal,
wasHorizontal = true, wasHorizontal = true,
content, content,
notes,
slide,
sectionStack = []; sectionStack = [];
// iterate until all blocks between separators are stacked up // iterate until all blocks between separators are stacked up
@ -126,25 +122,14 @@
// pluck slide content from markdown input // pluck slide content from markdown input
content = markdown.substring( lastIndex, matches.index ); content = markdown.substring( lastIndex, matches.index );
noteMatch = content.split( notesSeparatorRegex );
if( noteMatch.length === 2 ) {
content = noteMatch[0];
notes = noteMatch[1].trim();
}
slide = {
content: content,
notes: notes || ''
};
if( isHorizontal && wasHorizontal ) { if( isHorizontal && wasHorizontal ) {
// add to horizontal stack // add to horizontal stack
sectionStack.push( slide ); sectionStack.push( content );
} }
else { else {
// add to vertical stack // add to vertical stack
sectionStack[sectionStack.length-1].push( slide ); sectionStack[sectionStack.length-1].push( content );
} }
lastIndex = separatorRegex.lastIndex; lastIndex = separatorRegex.lastIndex;
@ -160,12 +145,16 @@
for( var i = 0, len = sectionStack.length; i < len; i++ ) { for( var i = 0, len = sectionStack.length; i < len; i++ ) {
// vertical // vertical
if( sectionStack[i].propertyIsEnumerable( length ) && typeof sectionStack[i].splice === 'function' ) { if( sectionStack[i].propertyIsEnumerable( length ) && typeof sectionStack[i].splice === 'function' ) {
markdownSections += '<section '+ options.attributes +'>' + markdownSections += '<section '+ options.attributes +'>';
'<section data-markdown>' + sectionStack[i].map( createMarkdownSlide ).join( '</section><section data-markdown>' ) + '</section>' +
'</section>'; sectionStack[i].forEach( function( child ) {
markdownSections += '<section data-markdown>' + createMarkdownSlide( child, options ) + '</section>';
} );
markdownSections += '</section>';
} }
else { else {
markdownSections += '<section '+ options.attributes +' data-markdown>' + createMarkdownSlide( sectionStack[i] ) + '</section>'; markdownSections += '<section '+ options.attributes +' data-markdown>' + createMarkdownSlide( sectionStack[i], options ) + '</section>';
} }
} }