aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-11 20:12:04 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-11 20:12:04 +0100
commitc57b900666a82b4ccce033a923e53906255078c0 (patch)
treec8619bf48c3bca17ea3c429194b96c0b3937e16b
parent57622e1584e7367aa41d4a09f8db33c703a6a0df (diff)
Don't guess what the input for conversion is
-rw-r--r--lib/docx-reader.js11
-rw-r--r--lib/index.js4
-rw-r--r--tests/docx-reader.tests.js4
-rw-r--r--tests/mammoth.tests.js6
4 files changed, 15 insertions, 10 deletions
diff --git a/lib/docx-reader.js b/lib/docx-reader.js
index fcc69fe..832ff31 100644
--- a/lib/docx-reader.js
+++ b/lib/docx-reader.js
@@ -15,10 +15,15 @@ var DocumentXmlReader = require("./document-xml-reader").DocumentXmlReader;
var Result = require("./results").Result;
-function read(docxFile) {
- if (_.isString(docxFile)) {
+function read(options) {
+ var docxFile;
+ if (options.path) {
var zipPath = docxFile;
- docxFile = openZip(zipPath);
+ docxFile = openZip(options.path);
+ } else if (options.file) {
+ docxFile = options.file;
+ } else {
+ return q.reject(new Error("Could not find file in options"));
}
return q.when(docxFile, function(docxFile) {
diff --git a/lib/index.js b/lib/index.js
index 778aad6..fb734e6 100644
--- a/lib/index.js
+++ b/lib/index.js
@@ -16,9 +16,9 @@ function Converter(options) {
this._documentConverter = new DocumentConverter(options);
}
-Converter.prototype.convertToHtml = function(docxFile) {
+Converter.prototype.convertToHtml = function(inputOptions) {
var documentConverter = this._documentConverter;
- return docxReader.read(docxFile)
+ return docxReader.read(inputOptions)
.then(function(documentResult) {
return documentResult.mapThen(function(document) {
return documentConverter.convertToHtml(document);
diff --git a/tests/docx-reader.tests.js b/tests/docx-reader.tests.js
index 58c5f6b..4fc487f 100644
--- a/tests/docx-reader.tests.js
+++ b/tests/docx-reader.tests.js
@@ -22,7 +22,7 @@ describe("docx-reader", function() {
var docxFile = createFakeDocxFile({
"word/document.xml": testData("simple/word/document.xml")
});
- return docxReader.read(docxFile).then(function(result) {
+ return docxReader.read({file: docxFile}).then(function(result) {
assert.deepEqual(expectedDocument, result.document);
});
});
@@ -32,7 +32,7 @@ describe("docx-reader", function() {
"word/document.xml": testData("hyperlinks/word/document.xml"),
"word/_rels/document.xml.rels": testData("hyperlinks/word/_rels/document.xml.rels")
});
- return docxReader.read(docxFile).then(function(result) {
+ return docxReader.read({file: docxFile}).then(function(result) {
var paragraph = result.document.children[0];
assert.equal(1, paragraph.children.length);
var hyperlink = paragraph.children[0];
diff --git a/tests/mammoth.tests.js b/tests/mammoth.tests.js
index 823a35b..9e81a84 100644
--- a/tests/mammoth.tests.js
+++ b/tests/mammoth.tests.js
@@ -14,7 +14,7 @@ describe('mammoth', function() {
test('should convert docx containing one one paragraph to single p element', function() {
var docxPath = path.join(__dirname, "test-data/single-paragraph.docx");
var converter = new mammoth.Converter();
- return converter.convertToHtml(docxPath).then(function(result) {
+ return converter.convertToHtml({path: docxPath}).then(function(result) {
assert.equal("<p>Walking on imported air</p>", result.html);
});
});
@@ -26,7 +26,7 @@ describe('mammoth', function() {
var converter = new mammoth.Converter({
defaultParagraphStyle: htmlPaths.topLevelElement("h1")
});
- return converter.convertToHtml(docxFile).then(function(result) {
+ return converter.convertToHtml({file: docxFile}).then(function(result) {
assert.equal("<h1>Hello.</h1>", result.html);
});
});
@@ -34,7 +34,7 @@ describe('mammoth', function() {
test('inline images are included in output', function() {
var converter = new mammoth.Converter();
var docxPath = path.join(__dirname, "test-data/tiny-picture.docx");
- return converter.convertToHtml(docxPath).then(function(result) {
+ return converter.convertToHtml({path: docxPath}).then(function(result) {
assert.equal(result.html, '<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAIAAAACUFjqAAAAAXNSR0IArs4c6QAAAAlwSFlzAAAOvgAADr4B6kKxwAAAABNJREFUKFNj/M+ADzDhlWUYqdIAQSwBE8U+X40AAAAASUVORK5CYII=" /></p>');
});
});