markdown plugin can now process slides that are added at runtime
authorHakim El Hattab <hakim.elhattab@gmail.com>
Fri, 6 Sep 2013 12:40:43 +0000 (08:40 -0400)
committerHakim El Hattab <hakim.elhattab@gmail.com>
Fri, 6 Sep 2013 12:40:43 +0000 (08:40 -0400)
plugin/markdown/markdown.js

index 739cc919718fd31ea22a9c39b5c517399eedce6c..42c847f088e2f40657f2828ae86bc27172368191 100755 (executable)
@@ -9,9 +9,8 @@
        }
        else {
                // Browser globals (root is window)
-               root.returnExports = factory( root.marked );
-               root.returnExports.processSlides();
-               root.returnExports.convertSlides();
+               root.RevealMarkdown = factory( root.marked );
+               root.RevealMarkdown.initialize();
        }
 }( this, function( marked ) {
 
 
                        var section = sections[i];
 
-                       var notes = section.querySelector( 'aside.notes' );
-                       var markdown = getMarkdownFromSlide( section );
+                       // Only parse the same slide once
+                       if( !section.getAttribute( 'data-markdown-parsed' ) ) {
 
-                       section.innerHTML = marked( markdown );
+                               section.setAttribute( 'data-markdown-parsed', true )
+
+                               var notes = section.querySelector( 'aside.notes' );
+                               var markdown = getMarkdownFromSlide( section );
+
+                               section.innerHTML = marked( markdown );
+
+                               // If there were notes, we need to re-add them after
+                               // having overwritten the section's HTML
+                               if( notes ) {
+                                       section.appendChild( notes );
+                               }
 
-                       // If there were notes, we need to re-add them after
-                       // having overwritten the section's HTML
-                       if( notes ) {
-                               section.appendChild( notes );
                        }
 
                }
 
        }
 
+       // API
        return {
+
+               initialize: function() {
+                       processSlides();
+                       convertSlides();
+               },
+
+               // TODO: Do these belong in the API?
                processSlides: processSlides,
                convertSlides: convertSlides,
                slidify: slidify
+
        };
 
 }));