From 4b0fe47bb6cbbded27666ece92a28ba0af885b13 Mon Sep 17 00:00:00 2001 From: VonC Date: Wed, 6 Nov 2013 11:06:03 +0100 Subject: [PATCH] Add slide attributes for single slide section case. --- plugin/markdown/markdown.js | 15 ++++++++++++--- test/test-markdown-attributes.html | 25 +++++++++++++++++++++++++ test/test-markdown-attributes.js | 5 +++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/plugin/markdown/markdown.js b/plugin/markdown/markdown.js index 00d2538..9564208 100755 --- a/plugin/markdown/markdown.js +++ b/plugin/markdown/markdown.js @@ -283,9 +283,18 @@ } else { - - section.innerHTML = createMarkdownSlide( getMarkdownFromSlide( section ) ); - + 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 ); } } diff --git a/test/test-markdown-attributes.html b/test/test-markdown-attributes.html index 262c6ae..cc03177 100644 --- a/test/test-markdown-attributes.html +++ b/test/test-markdown-attributes.html @@ -87,6 +87,31 @@ +
+ +
+ +
+ +
+ +
+ +
+ diff --git a/test/test-markdown-attributes.js b/test/test-markdown-attributes.js index 3e88341..a11f63b 100644 --- a/test/test-markdown-attributes.js +++ b/test/test-markdown-attributes.js @@ -36,6 +36,11 @@ Reveal.addEventListener( 'ready', function() { 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"' ); + }); + } ); Reveal.initialize(); -- 2.26.2