diff options
| -rw-r--r-- | lib/html/simplify.js | 3 | ||||
| -rw-r--r-- | test/html/simplify.tests.js | 16 |
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/html/simplify.js b/lib/html/simplify.js index 081c3f8..e05bde2 100644 --- a/lib/html/simplify.js +++ b/lib/html/simplify.js @@ -37,6 +37,9 @@ function identity(value) { function appendChild(children, child) { var lastChild = children[children.length - 1]; if (child.type === "element" && !child.tag.fresh && lastChild && lastChild.type === "element" && child.tag.matchesElement(lastChild.tag)) { + if (child.tag.separator) { + appendChild(lastChild.children, ast.text(child.tag.separator)); + } child.children.forEach(function(grandChild) { // Mutation is fine since simplifying elements create a copy of the children. appendChild(lastChild.children, grandChild); diff --git a/test/html/simplify.tests.js b/test/html/simplify.tests.js index 50593ee..cec4dc5 100644 --- a/test/html/simplify.tests.js +++ b/test/html/simplify.tests.js @@ -103,6 +103,22 @@ test("empty elements are removed before collapsing", function() { ); }); +test("when separator is present then separator is prepended to collapsed element", function() { + var unseparatedPath = htmlPaths.elements([ + htmlPaths.element("pre", {}, {fresh: false}) + ]); + var separatedPath = htmlPaths.elements([ + htmlPaths.element("pre", {}, {fresh: false, separator: "\n"}) + ]); + assert.deepEqual( + html.simplify(concat( + pathToNodes(unseparatedPath, [text("Hello")]), + pathToNodes(separatedPath, [text(" the"), text("re")]) + )), + pathToNodes(unseparatedPath, [text("Hello"), text("\n"), text(" the"), text("re")]) + ); +}); + function simplifyNode(node) { return html.simplify([node]); } |
