From 914a12e9cfa6837cb3d875a90a49633989d03594 Mon Sep 17 00:00:00 2001 From: Hakim El Hattab Date: Sat, 20 Apr 2013 09:16:41 -0400 Subject: [PATCH] forward all attributes for markdown slides (#413) --- plugin/markdown/markdown.js | 41 +++++++++++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 9ec1bf8..48fcfbd 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -31,7 +31,29 @@ return ''; }; - var slidifyMarkdown = function(markdown, separator, vertical, state) { + var getForwardedAttributes = function(section) { + var attributes = section.attributes; + var result = []; + + for( var i = 0, len = attributes.length; i < len; i++ ) { + var name = attributes[i].name, + value = attributes[i].value; + + // disregard attributes that are used for markdown loading/parsing + if( /data\-(markdown|separator|vertical)/gi.test( name ) ) continue; + + if( value ) { + result.push( name + '=' + value ); + } + else { + result.push( name ); + } + } + + return result.join( ' ' ); + } + + var slidifyMarkdown = function(markdown, separator, vertical, attributes) { separator = separator || '^\n---\n$'; @@ -77,9 +99,16 @@ // flatten the hierarchical stack, and insert
tags for( var k = 0, klen = sectionStack.length; k < klen; k++ ) { - markdownSections += typeof sectionStack[k] === 'string' - ? '
' + twrap( sectionStack[k] ) + '
' - : '
' + sectionStack[k].map(twrap).join('
') + '
'; + // horizontal + if( typeof sectionStack[k] === 'string' ) { + markdownSections += '
' + twrap( sectionStack[k] ) + '
'; + } + // vertical + else { + markdownSections += '
' + + '
' + sectionStack[k].map(twrap).join('
') + '
' + + '
'; + } } return markdownSections; @@ -102,7 +131,7 @@ xhr.onreadystatechange = function () { if( xhr.readyState === 4 ) { if (xhr.status >= 200 && xhr.status < 300) { - section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical'), section.getAttribute('data-state')); + section.outerHTML = slidifyMarkdown( xhr.responseText, section.getAttribute('data-separator'), section.getAttribute('data-vertical'), getForwardedAttributes(section) ); } else { section.outerHTML = '
ERROR: The attempt to fetch ' + url + ' failed with the HTTP status ' + xhr.status + '. Check your browser\'s JavaScript console for more details.' + @@ -121,7 +150,7 @@ } else if( section.getAttribute('data-separator') ) { var markdown = stripLeadingWhitespace(section); - section.outerHTML = slidifyMarkdown( markdown, section.getAttribute('data-separator'), section.getAttribute('data-vertical') ); + section.outerHTML = slidifyMarkdown( markdown, section.getAttribute('data-separator'), section.getAttribute('data-vertical'), getForwardedAttributes(section) ); } } -- 2.26.2