diff --git a/lib/documents.js b/lib/documents.js index cc6a2a33..af16a895 100644 --- a/lib/documents.js +++ b/lib/documents.js @@ -173,6 +173,7 @@ function Image(options) { return Buffer.from(arrayBuffer); }); }, + title: options.title, altText: options.altText, contentType: options.contentType }; diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index b9bdb57e..2f466d36 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -483,12 +483,11 @@ function BodyReader(options) { function readBlip(element, blip) { var properties = element.first("wp:docPr").attributes; - var altText = isBlank(properties.descr) ? properties.title : properties.descr; var blipImageFile = findBlipImageFile(blip); if (blipImageFile === null) { return emptyResultWithMessages([warning("Could not find image file for a:blip element")]); } else { - return readImage(blipImageFile, altText); + return readImage(blipImageFile, properties.descr, properties.title); } } @@ -532,12 +531,13 @@ function BodyReader(options) { }; } - function readImage(imageFile, altText) { + function readImage(imageFile, altText, title) { var contentType = contentTypes.findContentType(imageFile.path); var image = documents.Image({ readImage: imageFile.read, - altText: altText, + altText: isBlank(altText) ? title : altText, + title: title, contentType: contentType }); var warnings = supportedImageTypes[contentType] ? diff --git a/test/docx/body-reader.tests.js b/test/docx/body-reader.tests.js index c9fe7d3f..a55724d1 100644 --- a/test/docx/body-reader.tests.js +++ b/test/docx/body-reader.tests.js @@ -1052,13 +1052,15 @@ test("when v:imagedata element has no relationship ID then it is ignored with wa test("can read inline pictures", function() { var drawing = createInlineImage({ blip: createEmbeddedBlip(IMAGE_RELATIONSHIP_ID), - description: "It's a hat" + description: "It's a hat", + title: "Sombrero" }); var result = readEmbeddedImage(drawing); return promiseThat(result, isSuccess(contains(isImage({ altText: "It's a hat", + title: "Sombrero", contentType: "image/png", buffer: IMAGE_BUFFER })))); @@ -1073,6 +1075,7 @@ test("alt text title is used if alt text description is missing", function() { var result = readEmbeddedImage(drawing); return promiseThat(result, isSuccess(contains(isImage({ + title: "It's a hat", altText: "It's a hat" })))); }); @@ -1087,7 +1090,8 @@ test("alt text title is used if alt text description is blank", function() { var result = readEmbeddedImage(drawing); return promiseThat(result, isSuccess(contains(isImage({ - altText: "It's a hat" + altText: "It's a hat", + title: "It's a hat" })))); }); @@ -1101,7 +1105,8 @@ test("alt text description is preferred to alt text title", function() { var result = readEmbeddedImage(drawing); return promiseThat(result, isSuccess(contains(isImage({ - altText: "It's a hat" + altText: "It's a hat", + title: "hat" })))); });