diff options
| -rw-r--r-- | lib/document-to-html.js | 8 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 7 |
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js index ddb8848..1cbde9f 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -1,5 +1,6 @@ var promises = require("./promises"); var async = require("async"); +var beautifyHtml = require("js-beautify/js/lib/beautify-html") var htmlPaths = require("./html-paths"); var HtmlGenerator = require("./html-generator").HtmlGenerator; @@ -28,8 +29,11 @@ function DocumentConverter(options) { return promises.nfcall(elementToHtml, document, html, messages).then(function() { html.closeAll(); - - return new results.Result(html.asString(), messages); + var htmlString = html.asString(); + if (options.prettyPrint) { + htmlString = beautifyHtml.html_beautify(htmlString, {indent_size: 2}); + } + return new results.Result(htmlString, messages); }); } diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index 564eb8c..a59ade5 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -87,4 +87,11 @@ describe('mammoth', function() { assert.equal(result.value, '<ul><li>Apple</li><li>Banana</li></ul>'); }); }); + + test('newlines and indentation are used if prettyPrint is true', function() { + var docxPath = path.join(__dirname, "test-data/simple-list.docx"); + return mammoth.convertToHtml({path: docxPath}, {prettyPrint: true}).then(function(result) { + assert.equal(result.value, '<ul>\n <li>Apple</li>\n <li>Banana</li>\n</ul>'); + }); + }); }) |
