aboutsummaryrefslogtreecommitdiff
path: root/lib/index.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-11-19 14:53:45 +0000
committerMichael Williamson <mike@zwobble.org>2016-11-19 14:53:45 +0000
commita7146d18d1183fbe0203025f5e0e6aee5cd3775c (patch)
tree0742a812f4488265ca33ff7221bd97b78c500e53 /lib/index.js
parent599b3f17555a9d0c03ff040df6dca232b152a6f0 (diff)
Include embedded style map when explicit style map is set
Diffstat (limited to 'lib/index.js')
-rw-r--r--lib/index.js24
1 files changed, 12 insertions, 12 deletions
diff --git a/lib/index.js b/lib/index.js
index ae95371..212b0b7 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -1,3 +1,5 @@
+var _ = require("underscore");
+
var docxReader = require("./docx/docx-reader");
var docxStyleMap = require("./docx/style-map");
var DocumentConverter = require("./document-to-html").DocumentConverter;
@@ -27,24 +29,21 @@ function convertToMarkdown(input, options) {
}
function convert(input, options) {
- options = Object.create(options || {});
+ options = readOptions(options);
return unzip.openZip(input)
.tap(function(docxFile) {
- if (!options.styleMap) {
- return docxStyleMap.readStyleMap(docxFile).then(function(styleMap) {
- options.styleMap = styleMap || "";
- });
- }
+ return docxStyleMap.readStyleMap(docxFile).then(function(styleMap) {
+ options.embeddedStyleMap = styleMap;
+ });
})
.then(function(docxFile) {
- var fullOptions = readOptions(options);
return docxReader.read(docxFile, input)
.then(function(documentResult) {
- return documentResult.map(fullOptions.transformDocument);
+ return documentResult.map(options.transformDocument);
})
.then(function(documentResult) {
- return convertDocumentToHtml(documentResult, fullOptions);
+ return convertDocumentToHtml(documentResult, options);
});
});
}
@@ -55,9 +54,10 @@ function readEmbeddedStyleMap(input) {
}
function convertDocumentToHtml(documentResult, options) {
- var parsedOptions = Object.create(options);
- var styleMapResult = parseStyleMap(options.styleMap);
- parsedOptions.styleMap = styleMapResult.value;
+ var styleMapResult = parseStyleMap(options.readStyleMap());
+ var parsedOptions = _.extend({}, options, {
+ styleMap: styleMapResult.value
+ });
var documentConverter = new DocumentConverter(parsedOptions);
return documentResult.flatMapThen(function(document) {