From 0201587bec80aac0c1dcbf12c50ea6d459321585 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 10 Apr 2014 14:33:36 +0100 Subject: Indent appened HTML --- lib/html-writer.js | 7 ++++++- tests/html-writer.tests.js | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/html-writer.js b/lib/html-writer.js index be35d52..c144261 100644 --- a/lib/html-writer.js +++ b/lib/html-writer.js @@ -57,6 +57,11 @@ function prettyWriter() { writer.selfClosing(tagName, attributes); } + function append(html) { + indent(); + writer.append(html.replace("\n", "\n" + indentation)); + } + function insideIndentedElement() { return stack.length === 0 || indentedElements[stack[stack.length - 1]]; } @@ -76,7 +81,7 @@ function prettyWriter() { close: close, text: text, selfClosing: selfClosing, - append: writer.append + append: append }; } diff --git a/tests/html-writer.tests.js b/tests/html-writer.tests.js index de8b76f..c40cda4 100644 --- a/tests/html-writer.tests.js +++ b/tests/html-writer.tests.js @@ -66,4 +66,12 @@ describe('html-writer', function() { writer.close("p"); return assert.equal(writer.asString(), "

\n
\n

"); }); + + test('newlines in appended HTML are indented', function() { + var writer = htmlWriter.writer({prettyPrint: true}); + writer.open("p"); + writer.append("One\nTwo"); + writer.close("p"); + return assert.equal(writer.asString(), "

\n One\n Two\n

"); + }); }) -- cgit v1.2.3