From ad64ee06bd810b02f60b474b12d397eb4e95bdff Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 25 Jul 2013 09:40:19 +0200 Subject: [PATCH 1/1] Fixing xml output after removing text with white space --- modules/documentCanvas/canvas/canvas.test3.js | 23 +++++++++++++++++++ .../documentCanvas/canvas/documentElement.js | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/modules/documentCanvas/canvas/canvas.test3.js b/modules/documentCanvas/canvas/canvas.test3.js index 50f03e9..eeab1b2 100644 --- a/modules/documentCanvas/canvas/canvas.test3.js +++ b/modules/documentCanvas/canvas/canvas.test3.js @@ -1212,6 +1212,29 @@ describe('Canvas', function() { expect(xmlOut).to.equal(xmlIn); }); + it('keeps white space after detaching text element', function() { + var xmlIn = '
header
\ + \ + text1\ + \ +
', + expectedXmlOut = '
header
\ + \ + \ + \ +
', + 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); + }); + }) }) }); diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index b2625e1..8ef918a 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -211,7 +211,7 @@ $.extend(DocumentNodeElement.prototype, { 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); -- 2.20.1