@@ -694,34 +694,52 @@ private ReadResult readImagedata(XmlElement element) {
694694
695695 private ReadResult readInline (XmlElement element ) {
696696 XmlElementLike properties = element .findChildOrEmpty ("wp:docPr" );
697+
697698 Optional <String > altText = Optionals .first (
698699 properties .getAttributeOrNone ("descr" ).filter (description -> !description .trim ().isEmpty ()),
699700 properties .getAttributeOrNone ("title" )
700701 );
702+
703+ XmlElementLike hlinkClickElement = properties .findChildOrEmpty ("a:hlinkClick" );
704+ Optional <String > href = hlinkClickElement .getAttributeOrNone ("r:id" )
705+ .map (relationships ::findTargetByRelationshipId );
706+
701707 XmlElementList blips = element .findChildren ("a:graphic" )
702708 .findChildren ("a:graphicData" )
703709 .findChildren ("pic:pic" )
704710 .findChildren ("pic:blipFill" )
705711 .findChildren ("a:blip" );
706- return readBlips (blips , altText );
712+ return readBlips (blips , altText , href );
707713 }
708714
709- private ReadResult readBlips (XmlElementList blips , Optional <String > altText ) {
710- return ReadResult .flatMap (blips , blip -> readBlip (blip , altText ));
715+ private ReadResult readBlips (
716+ XmlElementList blips ,
717+ Optional <String > altText ,
718+ Optional <String > href
719+ ) {
720+ return ReadResult .flatMap (blips , blip -> readBlip (blip , altText , href ));
711721 }
712722
713- private ReadResult readBlip (XmlElement blip , Optional <String > altText ) {
714- Optional <String > embedRelationshipId = blip .getAttributeOrNone ("r:embed" );
715- Optional <String > linkRelationshipId = blip .getAttributeOrNone ("r:link" );
716- if (embedRelationshipId .isPresent ()) {
717- String imagePath = relationshipIdToDocxPath (embedRelationshipId .get ());
718- return readImage (imagePath , altText , () -> Archives .getInputStream (file , imagePath ));
719- } else if (linkRelationshipId .isPresent ()) {
720- String imagePath = relationships .findTargetByRelationshipId (linkRelationshipId .get ());
721- return readImage (imagePath , altText , () -> fileReader .getInputStream (imagePath ));
722- } else {
723+ private ReadResult readBlip (
724+ XmlElement blip ,
725+ Optional <String > altText ,
726+ Optional <String > href
727+ ) {
728+ Optional <BlipImage > blipImage = findBlipImage (blip );
729+
730+ if (!blipImage .isPresent ()) {
723731 return ReadResult .emptyWithWarning ("Could not find image file for a:blip element" );
724732 }
733+
734+ ReadResult result = readImage (blipImage .get ().path , altText , blipImage .get ().open );
735+
736+ if (!href .isPresent ()) {
737+ return result ;
738+ }
739+
740+ return result .map (imageElements -> list (
741+ new Hyperlink (href , Optional .empty (), Optional .empty (), imageElements )
742+ ));
725743 }
726744
727745 private ReadResult readImage (String imagePath , Optional <String > altText , InputStreamSupplier open ) {
@@ -736,6 +754,36 @@ private ReadResult readImage(String imagePath, Optional<String> altText, InputSt
736754 }
737755 }
738756
757+ private static class BlipImage {
758+ private final String path ;
759+ private final InputStreamSupplier open ;
760+
761+ public BlipImage (String path , InputStreamSupplier open ) {
762+ this .path = path ;
763+ this .open = open ;
764+ }
765+ }
766+
767+ private Optional <BlipImage > findBlipImage (XmlElement blip ) {
768+ Optional <String > embedRelationshipId = blip .getAttributeOrNone ("r:embed" );
769+ Optional <String > linkRelationshipId = blip .getAttributeOrNone ("r:link" );
770+ if (embedRelationshipId .isPresent ()) {
771+ String imagePath = relationshipIdToDocxPath (embedRelationshipId .get ());
772+ return Optional .of (new BlipImage (
773+ imagePath ,
774+ () -> Archives .getInputStream (file , imagePath )
775+ ));
776+ } else if (linkRelationshipId .isPresent ()) {
777+ String imagePath = relationships .findTargetByRelationshipId (linkRelationshipId .get ());
778+ return Optional .of (new BlipImage (
779+ imagePath ,
780+ () -> fileReader .getInputStream (imagePath )
781+ ));
782+ } else {
783+ return Optional .empty ();
784+ }
785+ }
786+
739787 private ReadResult readSdt (XmlElement element ) {
740788 ReadResult contentResult = readElements (
741789 element .findChildOrEmpty ("w:sdtContent" ).getChildren ()
0 commit comments