aboutsummaryrefslogtreecommitdiff
path: root/lib/main.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/main.js')
-rw-r--r--lib/main.js72
1 files changed, 42 insertions, 30 deletions
diff --git a/lib/main.js b/lib/main.js
index 1b56558..26d146a 100644
--- a/lib/main.js
+++ b/lib/main.js
@@ -9,39 +9,51 @@ function main(argv) {
var docxPath = argv["docx-path"];
var outputPath = argv["output-path"];
var outputDir = argv["output-dir"];
+ var styleMapPath = argv["style-map"];
- var options = {};
-
- if (outputDir) {
- var basename = path.basename(docxPath, ".docx");
- outputPath = path.join(outputDir, basename + ".html");
- var imageIndex = 0;
- options.convertImage = function(element, html, messages, callback) {
- imageIndex++;
- var extension = element.contentType.split("/")[1];
- var filename = imageIndex + "." + extension;
-
- element.read().then(function(imageBuffer) {
- var imagePath = path.join(outputDir, filename);
- return promises.nfcall(fs.writeFile, imagePath, imageBuffer);
- }).then(function() {
- var attributes = {src: filename};
- if (element.altText) {
- attributes.alt = element.altText;
- }
- html.selfClosing(htmlPaths.element("img", attributes));
- callback();
- }).fail(callback);
+ readStyleMap(styleMapPath).then(function(styleMap) {
+ var options = {
+ styleMap: styleMap
};
+
+ if (outputDir) {
+ var basename = path.basename(docxPath, ".docx");
+ outputPath = path.join(outputDir, basename + ".html");
+ var imageIndex = 0;
+ options.convertImage = function(element, html, messages, callback) {
+ imageIndex++;
+ var extension = element.contentType.split("/")[1];
+ var filename = imageIndex + "." + extension;
+
+ element.read().then(function(imageBuffer) {
+ var imagePath = path.join(outputDir, filename);
+ return promises.nfcall(fs.writeFile, imagePath, imageBuffer);
+ }).then(function() {
+ var attributes = {src: filename};
+ if (element.altText) {
+ attributes.alt = element.altText;
+ }
+ html.selfClosing(htmlPaths.element("img", attributes));
+ callback();
+ }).fail(callback);
+ };
+ }
+
+ return mammoth.convertToHtml({path: docxPath}, options)
+ .then(function(result) {
+ var outputStream = outputPath ? fs.createWriteStream(outputPath) : process.stdout;
+
+ outputStream.write(result.value);
+ })
+ }).done();
+}
+
+function readStyleMap(styleMapPath) {
+ if (styleMapPath) {
+ return promises.nfcall(fs.readFile, styleMapPath, "utf8");
+ } else {
+ return promises.resolve(null);
}
-
- mammoth.convertToHtml({path: docxPath}, options)
- .then(function(result) {
- var outputStream = outputPath ? fs.createWriteStream(outputPath) : process.stdout;
-
- outputStream.write(result.value);
- })
- .done();
}
module.exports = main;