diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-07 20:04:58 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-07 20:04:58 +0100 |
| commit | e5e37a6f2cfa04e146d534028fbf291aac2a9fe2 (patch) | |
| tree | 82f731589d4534b51b2dd1caf4b51848c0468eb1 /lib/docx | |
| parent | 97144ee9f557ef4886456972d36583b6b62685d2 (diff) | |
Add support for external images
Diffstat (limited to 'lib/docx')
| -rw-r--r-- | lib/docx/body-reader.js | 15 | ||||
| -rw-r--r-- | lib/docx/docx-reader.js | 12 |
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 25a263a..4126fde 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -11,6 +11,7 @@ function BodyReader(options) { var relationships = options.relationships; var contentTypes = options.contentTypes; var docxFile = options.docxFile; + var files = options.files; var numbering = options.numbering; var styles = options.styles; @@ -216,9 +217,17 @@ function BodyReader(options) { } function readBlip(element, blip) { - var relationshipId = blip.attributes["r:embed"]; - var imagePath = joinZipPath("word", relationships[relationshipId].target); - var readImage = docxFile.read.bind(docxFile, imagePath); + var embedRelationshipId = blip.attributes["r:embed"]; + var linkRelationshipid = blip.attributes["r:link"]; + var imagePath; + var readImage; + if (embedRelationshipId) { + imagePath = joinZipPath("word", relationships[embedRelationshipId].target); + readImage = docxFile.read.bind(docxFile, imagePath); + } else { + imagePath = relationships[linkRelationshipid].target; + readImage = files.read.bind(files, imagePath); + } var altText = element.first("wp:docPr").attributes.descr; var contentType = contentTypes.findContentType(imagePath); diff --git a/lib/docx/docx-reader.js b/lib/docx/docx-reader.js index 9b1ec9a..8627022 100644 --- a/lib/docx/docx-reader.js +++ b/lib/docx/docx-reader.js @@ -1,5 +1,7 @@ exports.read = read; +var path = require("path"); + var promises = require("../promises"); var documents = require("../documents"); var Result = require("../results").Result; @@ -12,14 +14,17 @@ var contentTypesReader = require("./content-types-reader"); var numberingXml = require("./numbering-xml"); var stylesReader = require("./styles-reader"); var notesReader = require("./notes-reader"); +var Files = require("./files").Files; -function read(docxFile) { +function read(docxFile, input) { + input = input || {}; return promises.props({ contentTypes: readContentTypesFromZipFile(docxFile), numbering: readNumberingFromZipFile(docxFile), styles: readStylesFromZipFile(docxFile), - docxFile: docxFile + docxFile: docxFile, + files: new Files(input.path ? path.dirname(input.path) : null) }).also(function(result) { return { footnotes: readXmlFileWithBody("footnotes", result, function(bodyReader, xml) { @@ -80,7 +85,8 @@ function readXmlFileWithBody(name, options, func) { contentTypes: options.contentTypes, docxFile: options.docxFile, numbering: options.numbering, - styles: options.styles + styles: options.styles, + files: options.files }); return readXmlFromZipFile(options.docxFile, "word/" + name + ".xml") .then(function(xml) { |
