ERROR: The attempt to fetch ' + url + ' failed with the HTTP status ' + xhr.status +
- '. Check your browser\'s JavaScript console for more details.' +
- 'Remember that you need to serve the presentation HTML from a HTTP server and the Markdown file must be there too.
';
- }
- }
- };
+ if( value ) {
+ result.push( name + '=' + value );
+ }
+ else {
+ result.push( name );
+ }
+ }
- xhr.open('GET', url, false);
- try {
- xhr.send();
- } catch (e) {
- alert('Failed to get the Markdown file ' + url + '. Make sure that the presentation and the file are served by a HTTP server and the file can be found there. ' + e);
- }
+ return result.join( ' ' );
- } else if( section.getAttribute('data-separator') ) {
+ };
- var markdown = stripLeadingWhitespace(section);
- section.outerHTML = slidifyMarkdown( markdown, section.getAttribute('data-separator'), section.getAttribute('data-vertical'), section.getAttribute('data-notes'), getForwardedAttributes(section) );
+ var slidifyMarkdown = function( markdown, separator, vertical, notes, attributes ) {
- }
- }
+ separator = separator || '^\n---\n$';
+ notes = notes || 'note:';
- };
+ var separatorRegex = new RegExp( separator + ( vertical ? '|' + vertical : '' ), 'mg' ),
+ horizontalSeparatorRegex = new RegExp( separator ),
+ notesSeparatorRegex = new RegExp( notes, 'mgi' ),
+ matches,
+ noteMatch,
+ lastIndex = 0,
+ isHorizontal,
+ wasHorizontal = true,
+ content,
+ asideContent,
+ slide,
+ sectionStack = [],
+ markdownSections = '';
+
+ // iterate until all blocks between separators are stacked up
+ while( matches = separatorRegex.exec( markdown ) ) {
+ asideContent = null;
- var queryMarkdownSlides = function() {
+ // determine direction (horizontal by default)
+ isHorizontal = horizontalSeparatorRegex.test( matches[0] );
- var sections = document.querySelectorAll( '[data-markdown]');
+ if( !isHorizontal && wasHorizontal ) {
+ // create vertical stack
+ sectionStack.push( [] );
+ }
- for( var j = 0, jlen = sections.length; j < jlen; j++ ) {
+ // pluck slide content from markdown input
+ content = markdown.substring( lastIndex, matches.index );
+ noteMatch = content.split( notesSeparatorRegex );
- makeHtml(sections[j]);
+ if( noteMatch.length === 2 ) {
+ content = noteMatch[0];
+ asideContent = noteMatch[1].trim();
+ }
- }
+ slide = {
+ content: content,
+ asideContent: asideContent || ''
+ };
- };
+ if( isHorizontal && wasHorizontal ) {
+ // add to horizontal stack
+ sectionStack.push(slide);
+ } else {
+ // add to vertical stack
+ sectionStack[sectionStack.length-1].push(slide);
+ }
- var makeHtml = function(section) {
+ lastIndex = separatorRegex.lastIndex;
+ wasHorizontal = isHorizontal;
+ }
- var notes = section.querySelector( 'aside.notes' );
+ // add the remaining slide
+ (wasHorizontal ? sectionStack : sectionStack[sectionStack.length-1]).push(markdown.substring(lastIndex));
- var markdown = stripLeadingWhitespace(section);
+ // flatten the hierarchical stack, and insert