aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-01 16:25:39 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-01 16:25:39 +0100
commit7a69fe97883ae27c51437c400cc08861dfa02b3c (patch)
tree58473582feb3aa40fcb4c68de7f9d2fc58b2fe7d
parente5a8d1bcce3a611bd3cd266ef36431a0c444fdde (diff)
Preserve messages in Converter
-rw-r--r--lib/docx-reader.js6
-rw-r--r--lib/index.js9
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/docx-reader.js b/lib/docx-reader.js
index b1e5627..e01d253 100644
--- a/lib/docx-reader.js
+++ b/lib/docx-reader.js
@@ -146,6 +146,12 @@ Result.prototype.map = function(func) {
return new Result(func(this.value), this.messages);
};
+Result.prototype.mapThen = function(func) {
+ return func(this.value).then(function(resultValue) {
+ return new Result(resultValue, this.messages);
+ });
+};
+
function warning(message) {
return {
type: "warning",
diff --git a/lib/index.js b/lib/index.js
index 83f1572..96ba751 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -19,7 +19,12 @@ function Converter(options) {
Converter.prototype.convertToHtml = function(docxFile) {
var documentConverter = this._documentConverter;
return docxReader.read(docxFile)
- .then(function(result) {
- return documentConverter.convertToHtml(result.document);
+ .then(function(documentResult) {
+ return documentResult.mapThen(function(document) {
+ return documentConverter.convertToHtml(document);
+ });
+ }).then(function(result) {
+ result.html = result.value.html;
+ return result;
});
}