From 2596c1c7122096874d00d7c5392d4ffb482e31b6 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 7 Sep 2015 20:39:54 +0100 Subject: Continue with warning when failing to read image --- lib/document-to-html.js | 13 ++++++++++++- lib/docx/files.js | 16 +++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/document-to-html.js b/lib/document-to-html.js index 907d62c..8a7cec0 100644 --- a/lib/document-to-html.js +++ b/lib/document-to-html.js @@ -174,6 +174,17 @@ function DocumentConversion(options) { }; }); }); + + function recoveringConvertImage(convertImage) { + return function(image, html, messages, callback) { + convertImage(image, html, messages, function(error) { + if (error) { + messages.push(results.warning(error.message)); + } + callback(); + }); + }; + } function noteHtmlId(note) { return htmlId(note.noteType + "-" + note.noteId); @@ -315,7 +326,7 @@ function DocumentConversion(options) { } }); }, - "image": options.convertImage || defaultConvertImage, + "image": recoveringConvertImage(options.convertImage || defaultConvertImage), "table": convertTable, "tableRow": convertTableRow, "tableCell": convertTableCell, diff --git a/lib/docx/files.js b/lib/docx/files.js index 2d0963b..0e95197 100644 --- a/lib/docx/files.js +++ b/lib/docx/files.js @@ -2,6 +2,7 @@ var fs = require("fs"); var url = require("url"); var os = require("os"); var resolvePath = require("path").resolve; +var isAbsolutePath = require('path-is-absolute'); var promises = require("../promises"); @@ -12,7 +13,20 @@ exports.uriToPath = uriToPath; function Files(base) { function read(uri, encoding) { - return readFile(resolvePath(base, uriToPath(uri)), encoding); + return resolveUri(uri).then(function(path) { + return readFile(path, encoding); + }); + } + + function resolveUri(uri) { + var path = uriToPath(uri); + if (isAbsolutePath(path)) { + return promises.resolve(path); + } else if (base) { + return promises.resolve(resolvePath(base, path)); + } else { + return promises.reject(new Error("could not find external image '" + uri + "', path of input document is unknown")); + } } return { -- cgit v1.2.3