From 571fb67864c41e52352a5d3246be1b5f4cb2d3ae Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sat, 24 Aug 2013 16:13:24 -0400 Subject: [PATCH] fix bug where markdown notes in last slide would not parse #574 --- plugin/markdown/markdown.js | 41 ++++++++++++++----------------------- 1 file changed, 15 insertions(+), 26 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 31d22f1..dabc0d4 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -75,12 +75,12 @@ /** * 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 ) { - content += ''; + if( notesMatch.length === 2 ) { + content = notesMatch[0] + ''; } return ''; @@ -99,17 +99,13 @@ options.attributes = options.attributes || ''; var separatorRegex = new RegExp( options.separator + ( options.verticalSeparator ? '|' + options.verticalSeparator : '' ), 'mg' ), - horizontalSeparatorRegex = new RegExp( options.separator ), - notesSeparatorRegex = new RegExp( options.notesSeparator, 'mgi' ); + horizontalSeparatorRegex = new RegExp( options.separator ); var matches, - noteMatch, lastIndex = 0, isHorizontal, wasHorizontal = true, content, - notes, - slide, sectionStack = []; // iterate until all blocks between separators are stacked up @@ -126,25 +122,14 @@ // pluck slide content from markdown input 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 ) { // add to horizontal stack - sectionStack.push( slide ); + sectionStack.push( content ); } else { // add to vertical stack - sectionStack[sectionStack.length-1].push( slide ); + sectionStack[sectionStack.length-1].push( content ); } lastIndex = separatorRegex.lastIndex; @@ -160,12 +145,16 @@ for( var i = 0, len = sectionStack.length; i < len; i++ ) { // vertical if( sectionStack[i].propertyIsEnumerable( length ) && typeof sectionStack[i].splice === 'function' ) { - markdownSections += '
' + - '
' + sectionStack[i].map( createMarkdownSlide ).join( '
' ) + '
' + - '
'; + markdownSections += '
'; + + sectionStack[i].forEach( function( child ) { + markdownSections += '
' + createMarkdownSlide( child, options ) + '
'; + } ); + + markdownSections += '
'; } else { - markdownSections += '
' + createMarkdownSlide( sectionStack[i] ) + '
'; + markdownSections += '
' + createMarkdownSlide( sectionStack[i], options ) + '
'; } }