Fix previous element selection.
authorVonC <vonc@laposte.net>
Thu, 28 Nov 2013 21:10:23 +0000 (22:10 +0100)
committerVonC <vonc@laposte.net>
Sat, 30 Nov 2013 22:12:39 +0000 (23:12 +0100)
plugin/markdown/markdown.js

index 34458f225c7bbab6eb95169cd724e85c0a10f432..2f6fc4421f92ee3237ebf598683b2c5a1744dde5 100755 (executable)
         */
        function addAttributes( section, element, previousElement, separatorElementAttributes, separatorSectionAttributes ) {
 
-               console.log("*** element='" + element.innerHTML + "', nodeType='" + element.nodeType + "'");
+               console.log("*** element='" + element.tagName + "', nodeType='" + element.nodeType + "'");
                console.log("previousElement="+previousElement)
-               console.log("section=****"+section.outerHTML+"****");
+               //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++ ) {
                                childElement = element.childNodes[i];
-                               console.log("  Child element='" + childElement.innerHTML + "', type " + childElement.nodeType);
-                               if ( i > 0 && typeof element.childNodes[i-1].setAttribute == 'function' ) {
-                                       previousParentElement = element.childNodes[i-1];
+                               console.log("  Child element='" + childElement.tagName + "', type " + childElement.nodeType);
+                               if ( i > 0 ) {
+                                       j = i - 1;
+                                       while ( j >= 0 ) {
+                                               aPreviousChildElement = element.childNodes[j];
+                                               if ( typeof aPreviousChildElement.setAttribute == 'function' && aPreviousChildElement.tagName != "BR") {
+                                                       previousParentElement = aPreviousChildElement;
+                                                       break;
+                                               }
+                                               j = j - 1;
+                                       }
                                }
                                parentSection = section;
                                if( childElement.nodeName ==  "section" ) {