summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2014-04-10 15:22:39 +0100
committerMichael Williamson <mike@zwobble.org>2014-04-10 15:22:39 +0100
commit83e403b060e73b9cd28f1af22e6e8f0085e5ebec (patch)
tree6134b004dd82bd8da5f15d798a19c59ffa4c0742
parentd4e6defd5a5f0bb6fd7e248e4e21ca838a461910 (diff)
Add prettyPrint option to convertToHtml
-rw-r--r--lib/document-to-html.js2
-rw-r--r--lib/html-generator.js4
-rw-r--r--tests/mammoth.tests.js8
3 files changed, 11 insertions, 3 deletions
diff --git a/lib/document-to-html.js b/lib/document-to-html.js
index 16596d7..e8c393c 100644
--- a/lib/document-to-html.js
+++ b/lib/document-to-html.js
@@ -24,7 +24,7 @@ function DocumentConverter(options) {
function convertToHtml(document) {
var messages = [];
- var html = new HtmlGenerator();
+ var html = new HtmlGenerator({prettyPrint: options.prettyPrint});
return promises.nfcall(elementToHtml, document, html, messages).then(function() {
html.closeAll();
diff --git a/lib/html-generator.js b/lib/html-generator.js
index 870ee66..de0749c 100644
--- a/lib/html-generator.js
+++ b/lib/html-generator.js
@@ -5,9 +5,9 @@ var htmlWriter = require("./html-writer");
exports.HtmlGenerator = HtmlGenerator;
-function HtmlGenerator() {
+function HtmlGenerator(options) {
var stack = [];
- var writer = htmlWriter.writer();
+ var writer = htmlWriter.writer(options);
function text(value) {
if (value.length > 0) {
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 564eb8c..0f9241e 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -87,4 +87,12 @@ describe('mammoth', function() {
assert.equal(result.value, '<ul><li>Apple</li><li>Banana</li></ul>');
});
});
+
+ test('indentation is used if prettyPrint is true', function() {
+ var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
+ return mammoth.convertToHtml({path: docxPath}, {prettyPrint: true}).then(function(result) {
+ assert.equal(result.value, "<p>\n Walking on imported air\n</p>");
+ assert.deepEqual(result.messages, []);
+ });
+ });
})