markdown refactoring #507
authorHakim El Hattab <hakim.elhattab@gmail.com>
Tue, 27 Aug 2013 13:11:33 +0000 (09:11 -0400)
committerHakim El Hattab <hakim.elhattab@gmail.com>
Tue, 27 Aug 2013 13:11:43 +0000 (09:11 -0400)
plugin/markdown/markdown.js

index dabc0d4164c432c81d18112034cc138b865b33db..c5c2358689aec95bda3e72bb03a037dc50e30d05 100755 (executable)
@@ -3,7 +3,17 @@
  * markdown inside of presentations as well as loading
  * of external markdown documents.
  */
-(function(){
+(function( root, factory ) {
+       if( typeof exports === 'object' ) {
+               module.exports = factory( require( './marked' ) );
+       }
+       else {
+               // Browser globals (root is window)
+               root.returnExports = factory( root.marked );
+               root.returnExports.processSlides();
+               root.returnExports.convertSlides();
+       }
+}( this, function( marked ) {
 
        if( typeof marked === 'undefined' ) {
                throw 'The reveal.js Markdown plugin requires marked to be loaded';
         * Parses a data string into multiple slides based
         * on the passed in separator arguments.
         */
-       function slidifyMarkdown( markdown, options ) {
+       function slidify( markdown, options ) {
 
                options = options || {};
                options.separator = options.separator || '^\n---\n$';
 
        }
 
-       function loadExternalMarkdown() {
+       /**
+        * Parses any current data-markdown slides, splits
+        * multi-slide markdown into separate sections and
+        * handles loading of external markdown.
+        */
+       function processSlides() {
 
                var sections = document.querySelectorAll( '[data-markdown]'),
                        section;
                                        if( xhr.readyState === 4 ) {
                                                if ( xhr.status >= 200 && xhr.status < 300 ) {
 
-                                                       section.outerHTML = slidifyMarkdown( xhr.responseText, {
+                                                       section.outerHTML = slidify( xhr.responseText, {
                                                                separator: section.getAttribute( 'data-separator' ),
                                                                verticalSeparator: section.getAttribute( 'data-vertical' ),
                                                                notesSeparator: section.getAttribute( 'data-notes' ),
                        }
                        else if( section.getAttribute( 'data-separator' ) ) {
 
-                               section.outerHTML = slidifyMarkdown( getMarkdownFromSlide( section ), {
+                               section.outerHTML = slidify( getMarkdownFromSlide( section ), {
                                        separator: section.getAttribute( 'data-separator' ),
                                        verticalSeparator: section.getAttribute( 'data-vertical' ),
                                        notesSeparator: section.getAttribute( 'data-notes' ),
 
        }
 
-       function convertMarkdownToHTML() {
+       /**
+        * Converts any current data-markdown slides in the
+        * DOM to HTML.
+        */
+       function convertSlides() {
 
                var sections = document.querySelectorAll( '[data-markdown]');
 
 
        }
 
-       loadExternalMarkdown();
-       convertMarkdownToHTML();
+       return {
+               processSlides: processSlides,
+               convertSlides: convertSlides,
+               slidify: slidify
+       };
 
-})();
+}));