Fixes #790: superfluous padding in xml editor
authorRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 26 Aug 2010 13:52:29 +0000 (15:52 +0200)
committerRadek Czajka <radoslaw.czajka@nowoczesnapolska.org.pl>
Thu, 26 Aug 2010 13:52:53 +0000 (15:52 +0200)
redakcja/static/js/wiki/xslt.js

index 2bab378..a5093b0 100644 (file)
@@ -288,7 +288,11 @@ HTMLSerializer.prototype.serialize = function(rootElement, stripOuter)
                                self._serializeElement(token.node);
                                break;
                        case TEXT_NODE:
                                self._serializeElement(token.node);
                                break;
                        case TEXT_NODE:
-                               self.result += token.node.nodeValue;
+                               // collapse previous element's padding
+                               var i = 0;
+                               while (token.node.nodeValue[i] == '\n' && self.result[self.result.length - 1] == '\n')
+                                 i ++;
+                               self.result += token.node.nodeValue.substr(i);
                                break;
                };
        };
                                break;
                };
        };
@@ -372,7 +376,9 @@ HTMLSerializer.prototype._serializeElement = function(node) {
        };
 
        /* print out */
        };
 
        /* print out */
-       if (getPadding(tagName))
+
+       // at least one newline before padded elements
+       if (getPadding(tagName) && self.result[self.result.length - 1] != '\n')
                self.result += '\n';
 
        self.result += '<' + tagName;
                self.result += '\n';
 
        self.result += '<' + tagName;