diff options
| -rw-r--r-- | lib/html-writer.js | 7 | ||||
| -rw-r--r-- | tests/html-writer.tests.js | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/lib/html-writer.js b/lib/html-writer.js index 1b551ed..be35d52 100644 --- a/lib/html-writer.js +++ b/lib/html-writer.js @@ -52,6 +52,11 @@ function prettyWriter() { writer.text(value.replace("\n", "\n" + indentation)); } + function selfClosing(tagName, attributes) { + indent(); + writer.selfClosing(tagName, attributes); + } + function insideIndentedElement() { return stack.length === 0 || indentedElements[stack[stack.length - 1]]; } @@ -70,7 +75,7 @@ function prettyWriter() { open: open, close: close, text: text, - selfClosing: writer.selfClosing, + selfClosing: selfClosing, append: writer.append }; } diff --git a/tests/html-writer.tests.js b/tests/html-writer.tests.js index dc6cb1c..de8b76f 100644 --- a/tests/html-writer.tests.js +++ b/tests/html-writer.tests.js @@ -58,4 +58,12 @@ describe('html-writer', function() { writer.close("p"); return assert.equal(writer.asString(), "<p>\n One\n Two\n</p>"); }); + + test('self closing elements are indented', function() { + var writer = htmlWriter.writer({prettyPrint: true}); + writer.open("p"); + writer.selfClosing("br"); + writer.close("p"); + return assert.equal(writer.asString(), "<p>\n <br />\n</p>"); + }); }) |
