First refactoring
authorVonC <vonc@laposte.net>
Sun, 24 Nov 2013 20:27:30 +0000 (21:27 +0100)
committerVonC <vonc@laposte.net>
Sat, 30 Nov 2013 22:12:38 +0000 (23:12 +0100)
plugin/markdown/markdown.js
test/test-markdown-attributes.html
test/test-markdown-element-attributes.html

index 9564208f0378908b090c3f8a124fb75fd1d2e6c0..d39956990d414d2cca49a31ad5d67500aa6536a2 100755 (executable)
                        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 ) {
+        console.log("element='" + element.innerHTML + "', nodeType='" + element.nodeType + "'");
+               console.log("previousElement="+previousElement)
+               console.log("section=****"+section.outerHTML+"****");
+               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];
+                               console.log("  Child element='" + childElement.innerHTML + "'");
+                               if ( i > 0 ) {
+                                       previousParentElement = element.childNodes[i-1];
+                               }
+                               parentSection = section;
+                               if( childElement.nodeName ==  "section" ) {
+                                       parentSection = childElement ;
+                                       previousParentElement = childElement ;
+                               }
+                               addAttributes( parentSection, childElement, previousParentElement, separatorElementAttributes, separatorSectionAttributes );
                        }
                }
 
-               var nodeValue;
-               var elementTarget;
-
+               if ( element.nodeType == Node.COMMENT_NODE ) {
+                       if ( addAttributeInElement( element, previousElement, separatorElementAttributes ) == false ) {
+                               addAttributeInElement( element, section, separatorSectionAttributes);
+                       }
+               }
                // 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 );
+                       addAttributeInElement( element, element.parentNode, separatorElementAttributes );
                }
                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 );
+                               addAttributeInElement( attr, element, separatorElementAttributes );
                        }
                }
 
                                var markdown = getMarkdownFromSlide( section );
 
                                section.innerHTML = marked( markdown );
-                               addAttributes(  section, section.getAttribute( 'data-element-attributes' ) ||
+                               //console.log("markdown="+markdown);
+                               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
index cc0317706b17d903304267d3d99b3e8f40089f70..8f77dac5491d88607c16b261c587916a70ad95d5 100644 (file)
@@ -15,7 +15,7 @@
                <div id="qunit"></div>
                <div id="qunit-fixture"></div>
 
-               <div class="reveal" style="display: none;">
+               <div class="reveal" style="display: true;">
 
                        <div class="slides">
 
index 417ce30c086912a63e0948850eaa0c2b465c0f0b..e9f403898baade44408bbdb8bed3961ce5764803 100644 (file)
@@ -15,7 +15,7 @@
                <div id="qunit"></div>
                <div id="qunit-fixture"></div>
 
-               <div class="reveal" style="display: none;">
+               <div class="reveal" style="display: true;">
 
                        <div class="slides">
 
@@ -44,7 +44,7 @@
                                                ## Slide 2
 
 
-                                               Paragraph 1.2  
+                                               Paragraph 1.2
                                                multi-line {_class="fragment highlight-red"}
 
                                                Paragraph 2.2 {_class="fragment highlight-red"}