Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ function Image(options) {
return {
type: types.image,
read: options.readImage,
title: options.title,
altText: options.altText,
contentType: options.contentType
};
Expand Down
8 changes: 4 additions & 4 deletions lib/docx/body-reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -461,12 +461,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);
}
}

Expand Down Expand Up @@ -510,12 +509,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] ?
Expand Down
11 changes: 8 additions & 3 deletions test/docx/body-reader.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -987,13 +987,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
}))));
Expand All @@ -1008,6 +1010,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"
}))));
});
Expand All @@ -1022,7 +1025,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"
}))));
});

Expand All @@ -1036,7 +1040,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"
}))));
});

Expand Down