diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/docx/body-reader.js | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index c5d9b02..d6a20b0 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -218,22 +218,37 @@ function BodyReader(options) { } function readBlip(element, blip) { + var altText = element.first("wp:docPr").attributes.descr; + return readImage(findBlipImageFile(blip), altText); + } + + function findBlipImageFile(blip) { 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); + return findEmbeddedImageFile(embedRelationshipId); } else { - imagePath = relationships[linkRelationshipid].target; - readImage = files.read.bind(files, imagePath); + var imagePath = relationships[linkRelationshipid].target; + return { + path: imagePath, + read: files.read.bind(files, imagePath) + }; } - var altText = element.first("wp:docPr").attributes.descr; - var contentType = contentTypes.findContentType(imagePath); + } + + function findEmbeddedImageFile(relationshipId) { + var path = joinZipPath("word", relationships[relationshipId].target); + return { + path: path, + read: docxFile.read.bind(docxFile, path) + }; + } + + function readImage(imageFile, altText) { + var contentType = contentTypes.findContentType(imageFile.path); var image = documents.Image({ - readImage: readImage, + readImage: imageFile.read, altText: altText, contentType: contentType }); |
