Add slide attributes for single slide section case.
authorVonC <vonc@laposte.net>
Wed, 6 Nov 2013 10:06:03 +0000 (11:06 +0100)
committerVonC <vonc@laposte.net>
Wed, 6 Nov 2013 10:06:03 +0000 (11:06 +0100)
plugin/markdown/markdown.js
test/test-markdown-attributes.html
test/test-markdown-attributes.js

index 00d253803bb945df67958e93acaad41951729f3a..9564208f0378908b090c3f8a124fb75fd1d2e6c0 100755 (executable)
 
                        }
                        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 );
                        }
                }
 
index 262c6ae7e755d0e3897a9492c5603d7d1879af71..cc0317706b17d903304267d3d99b3e8f40089f70 100644 (file)
                                        </script>
                                </section>
 
+        <section data-markdown>
+          <script type="text/template">
+            <!-- slide-attributes: data-background="#ff0000" -->
+            ## Hello world
+          </script>
+        </section>
+
+        <section data-markdown>
+          <script type="text/template">
+            ## Hello world
+            <!-- slide-attributes: data-background="#ff0000" -->
+          </script>
+        </section>
+
+        <section data-markdown>
+          <script type="text/template">
+            ## Hello world
+
+            Test
+            <!-- slide-attributes: data-background="#ff0000" -->
+
+            More Test
+          </script>
+        </section>
+
                        </div>
 
                </div>
index 3e88341010d5078f7f64afdd35ac0aab23a7e452..a11f63bc08c00c7ac6b5d770d6a48b5bef3f5087 100644 (file)
@@ -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();