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;
};
};
};
/* 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;