diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-08-16 17:08:33 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-08-16 17:08:33 +0100 |
| commit | 92d74192ae0c014b7b7d9d648f8305745433e4c2 (patch) | |
| tree | 8d70994716d587ea549f313bf9c29151d5cbb2d4 | |
| parent | 42ea88fd99174ec0b86a71d5cd18244ea22dcadd (diff) | |
Add mammoth.readEmbeddedStyleMap
| -rw-r--r-- | lib/index.js | 7 | ||||
| -rw-r--r-- | tests/mammoth.tests.js | 16 |
2 files changed, 21 insertions, 2 deletions
diff --git a/lib/index.js b/lib/index.js index a07b409..5613312 100644 --- a/lib/index.js +++ b/lib/index.js @@ -14,6 +14,7 @@ exports.images = require("./images"); exports.transforms = require("./transforms"); exports.underline = require("./underline"); exports.embedStyleMap = embedStyleMap; +exports.readEmbeddedStyleMap = readEmbeddedStyleMap; function convertToHtml(input, options) { return convert(input, options); @@ -46,7 +47,11 @@ function convert(input, options) { return convertDocumentToHtml(documentResult, fullOptions); }); }); - +} + +function readEmbeddedStyleMap(input) { + return unzip.openZip(input) + .then(docxStyleMap.readStyleMap); } function convertDocumentToHtml(documentResult, options) { diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js index 10ba228..b7f4766 100644 --- a/tests/mammoth.tests.js +++ b/tests/mammoth.tests.js @@ -81,7 +81,7 @@ describe('mammoth', function() { }); }); - test('embedded style is used if present', function() { + test('embedded style map is used if present', function() { var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); return promises.nfcall(fs.readFile, docxPath) .then(function(buffer) { @@ -96,6 +96,20 @@ describe('mammoth', function() { }); }); + test('embedded style map can be retrieved', function() { + var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); + return promises.nfcall(fs.readFile, docxPath) + .then(function(buffer) { + return mammoth.embedStyleMap({buffer: buffer}, "p => h1"); + }) + .then(function(docx) { + return mammoth.readEmbeddedStyleMap({buffer: docx.toBuffer()}); + }) + .then(function(styleMap) { + assert.equal(styleMap, "p => h1"); + }); + }); + test('warning if style mapping is not understood', function() { var docxPath = path.join(__dirname, "test-data/single-paragraph.docx"); var options = { |
