diff options
| author | Michael Williamson <mike@zwobble.org> | 2014-01-07 21:40:46 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2014-01-07 21:40:46 +0000 |
| commit | 705973a152a3b3c9a03e40100529fa9559c925ce (patch) | |
| tree | 8f1383749f7cc58b30e27d2d7a3e5463d7923a26 | |
| parent | d9d55dece1861bbbf08f3688254447992cf1957f (diff) | |
Pass a plain document into transformDocument
| -rw-r--r-- | lib/index.js | 13 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 15 |
2 files changed, 22 insertions, 6 deletions
diff --git a/lib/index.js b/lib/index.js index 1928424..db77d99 100644 --- a/lib/index.js +++ b/lib/index.js @@ -23,7 +23,8 @@ var standardOptions = { style("p:ordered-list(3) => ul|ol > li > ul|ol > li > ol > li:fresh"), style("p:ordered-list(4) => ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh"), style("p:ordered-list(5) => ul|ol > li > ul|ol > li > ul|ol > li > ul|ol > li > ol > li:fresh") - ] + ], + transformDocument: identity }; function convertToHtml(input, options) { @@ -38,11 +39,7 @@ function convertToHtml(input, options) { return docxReader.read(input) .then(function(documentResult) { - if (fullOptions.transformDocument) { - return fullOptions.transformDocument(documentResult); - } else { - return documentResult; - } + return documentResult.map(fullOptions.transformDocument); }) .then(function(documentResult) { return convertDocumentToHtml(documentResult, fullOptions); @@ -55,3 +52,7 @@ function convertDocumentToHtml(documentResult, options) { return documentConverter.convertToHtml(document); }); } + +function identity(value) { + return value; +} diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index f0d87c8..08270a4 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -59,6 +59,21 @@ describe('mammoth', function() { }); }); + test('options.transformDocument is used to transform document if set', function() { + var docxFile = createFakeDocxFile({ + "word/document.xml": testData("simple/word/document.xml") + }); + var options = { + transformDocument: function(document) { + document.children[0].styleName = "Heading1"; + return document; + } + }; + return mammoth.convertToHtml({file: docxFile}, options).then(function(result) { + assert.equal("<h1>Hello.</h1>", result.value); + }); + }); + test('inline images are included in output', function() { var docxPath = path.join(__dirname, "test-data/tiny-picture.docx"); return mammoth.convertToHtml({path: docxPath}).then(function(result) { |
