From: Radek Czajka Date: Thu, 26 Aug 2010 13:52:29 +0000 (+0200) Subject: Fixes #790: superfluous padding in xml editor X-Git-Url: https://git.mdrn.pl/redakcja.git/commitdiff_plain/bcb522c4e4b570fb42b754d8b19dd8bd6bc87f18?ds=sidebyside Fixes #790: superfluous padding in xml editor --- diff --git a/redakcja/static/js/wiki/xslt.js b/redakcja/static/js/wiki/xslt.js index 2bab378d..a5093b04 100644 --- a/redakcja/static/js/wiki/xslt.js +++ b/redakcja/static/js/wiki/xslt.js @@ -288,7 +288,11 @@ HTMLSerializer.prototype.serialize = function(rootElement, stripOuter) 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; }; }; @@ -372,7 +376,9 @@ HTMLSerializer.prototype._serializeElement = function(node) { }; /* 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;