';
+ markdownSections += '';
sectionStack[i].forEach( function( child ) {
- matchAttributes = slideAttributesSeparatorRegex.exec( child );
- slideAttributes = matchAttributes ? matchAttributes[1] : "";
- child = matchAttributes ? child.replace( slideAttributesSeparatorRegex,"" ) : child
- markdownSections += '' + createMarkdownSlide( child, options ) + ' ';
+ markdownSections += '' + createMarkdownSlide( child, options ) + ' ';
} );
markdownSections += ' ';
}
else {
- matchAttributes = slideAttributesSeparatorRegex.exec( sectionStack[i] );
- slideAttributes = matchAttributes ? matchAttributes[1] : "";
- content = matchAttributes ? sectionStack[i].replace( slideAttributesSeparatorRegex,"" ) : sectionStack[i]
- markdownSections += '' + createMarkdownSlide( content, options ) + ' ';
+ markdownSections += '' + createMarkdownSlide( sectionStack[i], options ) + ' ';
}
}
+
return markdownSections;
}
@@ -240,12 +220,12 @@
xhr.onreadystatechange = function() {
if( xhr.readyState === 4 ) {
if ( xhr.status >= 200 && xhr.status < 300 ) {
+
section.outerHTML = slidify( xhr.responseText, {
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-vertical' ),
notesSeparator: section.getAttribute( 'data-notes' ),
- attributes: getForwardedAttributes( section ),
- slideAttributesSeparator: section.getAttribute( 'data-attributes' ),
+ attributes: getForwardedAttributes( section )
});
}
@@ -277,24 +257,12 @@
separator: section.getAttribute( 'data-separator' ),
verticalSeparator: section.getAttribute( 'data-vertical' ),
notesSeparator: section.getAttribute( 'data-notes' ),
- attributes: getForwardedAttributes( section ),
- slideAttributesSeparator: section.getAttribute( 'data-attributes' ),
+ attributes: getForwardedAttributes( section )
});
}
else {
- var content = getMarkdownFromSlide( section );
- var slideAttributesSeparatorRegex = new RegExp( section.getAttribute( 'data-attributes' ) || DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR, 'm' );
- var matchAttributes = slideAttributesSeparatorRegex.exec( content );
- if ( matchAttributes ) {
- var slideAttributes = matchAttributes[1];
- content = content.replace( slideAttributesSeparatorRegex,"" );
- var slideAttributesRegex = new RegExp( "([^\"= ]+?)=\"([^\"=]+?)\"", 'mg' );
- while( matchesAttributes = slideAttributesRegex.exec( slideAttributes ) ) {
- section.setAttribute( matchesAttributes[1], matchesAttributes[2] );
- }
- }
- section.innerHTML = createMarkdownSlide( content );
+ section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) );
}
}
@@ -319,40 +287,51 @@
var classes = matches[1];
nodeValue = nodeValue.substring( 0, matches.index ) + nodeValue.substring( mardownClassesInElementsRegex.lastIndex );
node.nodeValue = nodeValue;
-
while( matchesClass = mardownClassRegex.exec( classes ) ) {
elementTarget.setAttribute( matchesClass[1], matchesClass[2] );
}
+ return true;
}
-
+ return false;
}
/**
* Add attributes to the parent element of a text node,
* or the element of an attribute node.
*/
- function addAttributes( element, separator ) {
+ function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) {
- if( element.childNodes.length > 0 ) {
+ if ( element != null && element.childNodes != undefined && element.childNodes.length > 0 ) {
+ previousParentElement = element;
for( var i = 0; i < element.childNodes.length; i++ ) {
- addAttributes( element.childNodes[i], separator );
+ childElement = element.childNodes[i];
+ if ( i > 0 ) {
+ j = i - 1;
+ while ( j >= 0 ) {
+ aPreviousChildElement = element.childNodes[j];
+ if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR" ) {
+ previousParentElement = aPreviousChildElement;
+ break;
+ }
+ j = j - 1;
+ }
+ }
+ parentSection = section;
+ if( childElement.nodeName == "section" ) {
+ parentSection = childElement ;
+ previousParentElement = childElement ;
+ }
+ if ( typeof childElement.setAttribute == 'function' || childElement.nodeType == Node.COMMENT_NODE ) {
+ addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
+ }
}
}
- var nodeValue;
- var elementTarget;
-
- // From http://stackoverflow.com/questions/9178174/find-all-text-nodes
- if( element.nodeType == Node.TEXT_NODE && /\S/.test(element.nodeValue) ) {
- addAttributeInElement( element, element.parentNode, separator );
- }
- if( element.nodeType == Node.ELEMENT_NODE && element.attributes.length > 0 ) {
- for( var j = 0; j < element.attributes.length; j++ ){
- var attr = element.attributes[j];
- addAttributeInElement( attr, element, separator );
+ if ( element.nodeType == Node.COMMENT_NODE ) {
+ if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) {
+ addAttributeInElement( element, section, separatorSectionAttributes );
}
}
-
}
/**
@@ -376,9 +355,12 @@
var markdown = getMarkdownFromSlide( section );
section.innerHTML = marked( markdown );
- addAttributes( section, section.getAttribute( 'data-element-attributes' ) ||
+ addAttributes( section, section, null, section.getAttribute( 'data-element-attributes' ) ||
section.parentNode.getAttribute( 'data-element-attributes' ) ||
- DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR );
+ DEFAULT_ELEMENT_ATTRIBUTES_SEPARATOR,
+ section.getAttribute( 'data-attributes' ) ||
+ section.parentNode.getAttribute( 'data-attributes' ) ||
+ DEFAULT_SLIDE_ATTRIBUTES_SEPARATOR);
// If there were notes, we need to re-add them after
// having overwritten the section's HTML
diff --git a/test/test-markdown-attributes.html b/test/test-markdown-attributes.html
index cc031770..94c146f7 100644
--- a/test/test-markdown-attributes.html
+++ b/test/test-markdown-attributes.html
@@ -13,7 +13,7 @@
-
+
@@ -25,7 +25,7 @@
-
+
-
+
-
+ More Test
+
+
diff --git a/test/test-markdown-attributes.js b/test/test-markdown-attributes.js
index a11f63bc..3817fd37 100644
--- a/test/test-markdown-attributes.js
+++ b/test/test-markdown-attributes.js
@@ -2,44 +2,44 @@
Reveal.addEventListener( 'ready', function() {
- QUnit.module( 'Markdown' );
+ QUnit.module( 'Markdown' );
- test( 'Vertical separator', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 6, 'found six vertical slides' );
- });
+ test( 'Vertical separator', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 6, 'found six vertical slides' );
+ });
- test( 'Id on slide', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section#slide2' ).length, 1, 'found one slide with id slide2' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section a[href="#/slide2"]' ).length, 1, 'found one slide with a link to slide2' );
- });
+ test( 'Id on slide', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section#slide2' ).length, 1, 'found one slide with id slide2' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section a[href="#/slide2"]' ).length, 1, 'found one slide with a link to slide2' );
+ });
- test( 'data-background attributes', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A0C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#ff0000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C6916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
- });
+ test( 'data-background attributes', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A0C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#ff0000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C6916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
+ });
- test( 'data-transition attributes', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="zoom"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="fade"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
- strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="zoom"]' ).length, 1, 'found one slide with data-transition="zoom"' );
- });
+ test( 'data-transition attributes', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="zoom"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="fade"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="zoom"]' ).length, 1, 'found one slide with data-transition="zoom"' );
+ });
- test( 'data-background attributes with default separator', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A7C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#f70000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C7916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
- });
+ test( 'data-background attributes with default separator', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#A7C66B"]' ).length, 1, 'found one vertical slide with data-background="#A0C66B"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-background="#f70000"]' ).length, 1, 'found one vertical slide with data-background="#ff0000"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#C7916B"]' ).length, 1, 'found one slide with data-background="#C6916B"' );
+ });
- test( 'data-transition attributes with default separator', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="concave"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="page"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
- strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="concave"]' ).length, 1, 'found one slide with data-transition="zoom"' );
- });
+ test( 'data-transition attributes with default separator', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="concave"]' ).length, 1, 'found one vertical slide with data-transition="zoom"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section[data-transition="page"]' ).length, 1, 'found one vertical slide with data-transition="fade"' );
+ strictEqual( document.querySelectorAll( '.reveal .slides section [data-transition="concave"]' ).length, 1, 'found one slide with data-transition="zoom"' );
+ });
- test( 'data-transition attributes with inline content', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#ff0000"]' ).length, 3, 'found three horizontal slides with data-background="#ff0000"' );
- });
+ test( 'data-transition attributes with inline content', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides>section[data-background="#ff0000"]' ).length, 3, 'found three horizontal slides with data-background="#ff0000"' );
+ });
} );
diff --git a/test/test-markdown-element-attributes.html b/test/test-markdown-element-attributes.html
index 417ce30c..b638082b 100644
--- a/test/test-markdown-element-attributes.html
+++ b/test/test-markdown-element-attributes.html
@@ -4,7 +4,7 @@
- reveal.js - Test Markdown
+ reveal.js - Test Markdown Element Attributes
@@ -13,7 +13,7 @@
-
+
@@ -24,19 +24,23 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/test-markdown-element-attributes.js b/test/test-markdown-element-attributes.js
index e79806c6..4541077a 100644
--- a/test/test-markdown-element-attributes.js
+++ b/test/test-markdown-element-attributes.js
@@ -5,33 +5,41 @@ Reveal.addEventListener( 'ready', function() {
QUnit.module( 'Markdown' );
test( 'Vertical separator', function() {
- strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 2, 'found two slides' );
+ strictEqual( document.querySelectorAll( '.reveal .slides>section>section' ).length, 4, 'found four slides' );
});
- test( 'Attributes on vertical slides header', function() {
+ test( 'Attributes on element header in vertical slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.fade-out' ).length, 1, 'found one vertical slide with class fragment.fade-out on header' );
strictEqual( document.querySelectorAll( '.reveal .slides section>section h2.fragment.shrink' ).length, 1, 'found one vertical slide with class fragment.shrink on header' );
});
- test( 'Attributes on vertical slides paragraphs', function() {
+ test( 'Attributes on element paragraphs in vertical slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section>section p.fragment.grow' ).length, 2, 'found a vertical slide with two paragraphs with class fragment.grow' );
});
- test( 'Attributes on vertical slides list items', function() {
+ test( 'Attributes on element list items in vertical slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section>section li.fragment.roll-in' ).length, 3, 'found a vertical slide with three list items with class fragment.roll-in' );
});
- test( 'Attributes on horizontal slides paragraphs', function() {
+ test( 'Attributes on element paragraphs in horizontal slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-red' ).length, 4, 'found a horizontal slide with four paragraphs with class fragment.grow' );
});
- test( 'Attributes on horizontal slides list items', function() {
+ test( 'Attributes on element list items in horizontal slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section li.fragment.highlight-green' ).length, 5, 'found a horizontal slide with five list items with class fragment.roll-in' );
});
- test( 'Attributes on horizontal slides list items', function() {
+ test( 'Attributes on element list items in horizontal slides', function() {
strictEqual( document.querySelectorAll( '.reveal .slides section img.reveal.stretch' ).length, 1, 'found a horizontal slide with stretched image, class img.reveal.stretch' );
});
+ test( 'Attributes on elements in vertical slides with default element attribute separator', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides section h2.fragment.highlight-red' ).length, 2, 'found two h2 titles with fragment highlight-red in vertical slides with default element attribute separator' );
+ });
+
+ test( 'Attributes on elements in single slides with default element attribute separator', function() {
+ strictEqual( document.querySelectorAll( '.reveal .slides section p.fragment.highlight-blue' ).length, 3, 'found three elements with fragment highlight-blue in single slide with default element attribute separator' );
+ });
+
} );
Reveal.initialize();