fnp
/
fnpeditor.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
cf7c3b4
)
Fixing some xml output formatting problems
author
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 12:34:18 +0000
(14:34 +0200)
committer
Aleksander Łukasz
<aleksander.lukasz@nowoczesnapolska.org.pl>
Thu, 25 Jul 2013 12:34:18 +0000
(14:34 +0200)
modules/documentCanvas/canvas/canvas.js
patch
|
blob
|
history
modules/documentCanvas/canvas/canvas.test3.js
patch
|
blob
|
history
modules/documentCanvas/canvas/documentElement.js
patch
|
blob
|
history
diff --git
a/modules/documentCanvas/canvas/canvas.js
b/modules/documentCanvas/canvas/canvas.js
index
8882c1c
..
19c2a3f
100644
(file)
--- a/
modules/documentCanvas/canvas/canvas.js
+++ b/
modules/documentCanvas/canvas/canvas.js
@@
-320,8
+320,9
@@
$.extend(Canvas.prototype, {
},
toXML: function() {
},
toXML: function() {
- var parent = $('<div>');
- this.doc().toXML(parent, 0)
+ var parent = $('<div>'),
+ parts = this.doc().toXML(0);
+ parent.append(parts);
return parent.html();
}
});
return parent.html();
}
});
diff --git
a/modules/documentCanvas/canvas/canvas.test3.js
b/modules/documentCanvas/canvas/canvas.test3.js
index
51f4f0a
..
50f03e9
100644
(file)
--- a/
modules/documentCanvas/canvas/canvas.test3.js
+++ b/
modules/documentCanvas/canvas/canvas.test3.js
@@
-1185,7
+1185,31
@@
describe('Canvas', function() {
var xmlOut = c.toXML();
console.log(xmlOut);
expect(xmlOut).to.equal(xmlIn);
var xmlOut = c.toXML();
console.log(xmlOut);
expect(xmlOut).to.equal(xmlIn);
+ });
+
+ it('keeps white space around text node', function() {
+ var xmlIn = '<section>\
+ <header>header1</header>\
+ Some text surrounded by white space\
+ <header>header2</header>\
+ </section>',
+ c = canvas.fromXML(xmlIn);
+ var xmlOut = c.toXML();
+ expect(xmlOut).to.equal(xmlIn);
+ });
+
+ it('keeps white space around text node - last node case', function() {
+ var xmlIn = '<section>\
+ <header>header</header>\
+ \
+ Some text surrounded by white space\
+ \
+ </section>',
+ c = canvas.fromXML(xmlIn);
+
+ var xmlOut = c.toXML();
+ expect(xmlOut).to.equal(xmlIn);
});
})
});
})
diff --git
a/modules/documentCanvas/canvas/documentElement.js
b/modules/documentCanvas/canvas/documentElement.js
index
9178a5a
..
9359134
100644
(file)
--- a/
modules/documentCanvas/canvas/documentElement.js
+++ b/
modules/documentCanvas/canvas/documentElement.js
@@
-148,14
+148,6
@@
var manipulate = function(e, params, action) {
DocumentNodeElement.prototype = new DocumentElement();
DocumentNodeElement.prototype = new DocumentElement();
-var addParts = function(parts, parent) {
- var parentChildren = parent.contents();
- if(parentChildren.length > 2 && parentChildren[0].nodeType === Node.TEXT_NODE && parentChildren[1].nodeType == Node.TEXT_NODE) {
- $(parentChildren[0]).after(parts);
- } else {
- parent.prepend(parts);
- }
-}
$.extend(DocumentNodeElement.prototype, {
data: function() {
$.extend(DocumentNodeElement.prototype, {
data: function() {
@@
-165,7
+157,7
@@
$.extend(DocumentNodeElement.prototype, {
return dom.removeData(args[1]);
return dom.data.apply(dom, arguments);
},
return dom.removeData(args[1]);
return dom.data.apply(dom, arguments);
},
- toXML: function(
parent,
level) {
+ toXML: function(level) {
var node = $('<' + this.getWlxmlTag() + '>');
if(this.getWlxmlClass())
var node = $('<' + this.getWlxmlTag() + '>');
if(this.getWlxmlClass())
@@
-204,12
+196,30
@@
$.extend(DocumentNodeElement.prototype, {
var parts = addFormatting(node);
var parts = addFormatting(node);
- var children = this.children();
+ var children = this.children(),
+ childParts,
+ prevChildParts;
+
for(var i = children.length - 1; i >= 0; i--) {
for(var i = children.length - 1; i >= 0; i--) {
- children[i].toXML(node, level + 1);
- }
+ childParts = children[i].toXML(level + 1);
+
+ if(i === children.length - 1 && node.contents().length === 2) {
+ $(node.contents()[0]).after(childParts);
+ prevChildParts = childParts;
+ continue;
+ }
+
+ if(prevChildParts && prevChildParts.length > 1 && prevChildParts[0].nodeType === Node.TEXT_NODE && prevChildParts[1].nodeType === Node.TEXT_NODE) {
+ $(node.contents()[0]).after(childParts);
+ prevChildParts = childParts;
+ continue;
+ }
- addParts(parts, parent);
+ node.prepend(childParts);
+
+ prevChildParts = childParts;
+ }
+ return parts;
},
append: function(params) {
if(params.tag !== 'span')
},
append: function(params) {
if(params.tag !== 'span')
@@
-326,7
+336,7
@@
DocumentTextElement.prototype = new DocumentElement();
$.extend(DocumentTextElement.prototype, {
toXML: function(parent) {
$.extend(DocumentTextElement.prototype, {
toXML: function(parent) {
-
addParts(this.getText(), parent
);
+
return this.getText(
);
},
_setupDOMHandler: function(htmlElement) {
var $element = $(htmlElement);
},
_setupDOMHandler: function(htmlElement) {
var $element = $(htmlElement);