From 5b8d20f1cdca33a08cd0cb72af5b13c22653cea3 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Nov 2025 15:16:07 +0000 Subject: Handle hyperlinked wp:anchor and wp:inline elements --- lib/docx/body-reader.js | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/docx/body-reader.js b/lib/docx/body-reader.js index 826424b..febbbc2 100644 --- a/lib/docx/body-reader.js +++ b/lib/docx/body-reader.js @@ -586,14 +586,26 @@ function BodyReader(options) { } function readBlip(element, blip) { - var properties = element.first("wp:docPr").attributes; + var propertiesElement = element.firstOrEmpty("wp:docPr"); + var properties = propertiesElement.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, altText).map(function(imageElement) { + var hlinkClickElement = propertiesElement.firstOrEmpty("a:hlinkClick"); + var relationshipId = hlinkClickElement.attributes["r:id"]; + if (relationshipId) { + var href = relationships.findTargetByRelationshipId(relationshipId); + return new documents.Hyperlink([imageElement], {href: href}); + } else { + return imageElement; + } + }); } function isBlank(value) { -- cgit v1.2.3