Fixing xml output after removing text with white space
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 07:40:19 +0000 (09:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 12:34:52 +0000 (14:34 +0200)
modules/documentCanvas/canvas/canvas.test3.js
modules/documentCanvas/canvas/documentElement.js

index 50f03e9..eeab1b2 100644 (file)
@@ -1212,6 +1212,29 @@ describe('Canvas', function() {
                 expect(xmlOut).to.equal(xmlIn);
             });
 
                 expect(xmlOut).to.equal(xmlIn);
             });
 
+            it('keeps white space after detaching text element', function() {
+                var xmlIn = '<section><header>header</header>\
+                    \
+                text1\
+                    \
+            </section>',
+                    expectedXmlOut = '<section><header>header</header>\
+                    \
+                \
+                    \
+            </section>',
+                    c = canvas.fromXML(xmlIn),
+                    children = c.doc().children(),
+                    text = children[children.length-1];
+                
+                expect(text.getText()).to.equal('text1');
+
+                text.detach();
+
+                var xmlOut = c.toXML();
+                expect(xmlOut).to.equal(expectedXmlOut);
+            });
+
         })
     })
 });
         })
     })
 });
index b2625e1..8ef918a 100644 (file)
@@ -211,7 +211,7 @@ $.extend(DocumentNodeElement.prototype, {
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
             
         for(var i = children.length - 1; i >= 0; i--) {
             childParts = children[i].toXML(level + 1);
             
-            if(containsPrefixAndSuffix(i)) {
+            if(containsPrefixAndSuffix(i) && children[i] instanceof DocumentTextElement) {
                 $(node.contents()[0]).after(childParts);
             } else {
                 node.prepend(childParts);
                 $(node.contents()[0]).after(childParts);
             } else {
                 node.prepend(childParts);