@@ -205,7 +205,7 @@ data Slide = MetadataSlide { metadataSlideTitle :: [ParaElem]
205205data SlideElement = SlideElement Pixels Pixels Pixels Pixels Shape
206206 deriving (Show, Eq)
207207
208−data Shape = Pic FilePath Text.Pandoc.Definition.Attr [ParaElem]
208+data Shape = Pic PicProps FilePath Text.Pandoc.Definition.Attr [ParaElem]
209209 | GraphicFrame [Graphic] [ParaElem]
210210 | TextBox [Paragraph]
211211 deriving (Show, Eq)
@@ -327,6 +327,13 @@ instance Default RunProps where
327327 , rPropForceSize = Nothing
328328 }
329329
330+data PicProps = PicProps { picPropLink :: Maybe (URL, String)
331+ } deriving (Show, Eq)
332+
333+instance Default PicProps where
334+ def = PicProps { picPropLink = Nothing
335+ }
336+
330337--------------------------------------------------
331338
332339inlinesToParElems :: Monad m => [Inline] -> P m [ParaElem]
@@ -489,9 +496,15 @@ rowToParagraphs algns tblCells = do
489496
490497blockToShape :: PandocMonad m => Block -> P m Shape
491498blockToShape (Plain (il:_)) | Image attr ils (url, _) <- il =
492− Pic url attr <$> (inlinesToParElems ils)
499+ Pic def url attr <$> (inlinesToParElems ils)
493500blockToShape (Para (il:_)) | Image attr ils (url, _) <- il =
494− Pic url attr <$> (inlinesToParElems ils)
501+ Pic def url attr <$> (inlinesToParElems ils)
502+blockToShape (Plain (il:_)) | Link _ (il':_) target <- il
503+ , Image attr ils (url, _) <- il' =
504+ Pic def{picPropLink = Just target} url attr <$> (inlinesToParElems ils)
505+blockToShape (Para (il:_)) | Link _ (il':_) target <- il
506+ , Image attr ils (url, _) <- il' =
507+ Pic def{picPropLink = Just target} url attr <$> (inlinesToParElems ils)
495508blockToShape (Table caption algn _ hdrCells rows) = do
496509 caption' <- inlinesToParElems caption
497510 pageWidth <- presSizeWidth <$> asks envPresentationSize
@@ -781,7 +794,7 @@ presentationToArchive p@(Presentation _ slides) = do
781794combineShapes :: [Shape] -> [Shape]
782795combineShapes [] = []
783796combineShapes (s : []) = [s]
784−combineShapes (pic@(Pic _ _ _) : ss) = pic : combineShapes ss
797+combineShapes (pic@(Pic _ _ _ _) : ss) = pic : combineShapes ss
785798combineShapes ((TextBox []) : ss) = combineShapes ss
786799combineShapes (s : TextBox [] : ss) = combineShapes (s : ss)
787800combineShapes (s@(TextBox (p:ps)) : s'@(TextBox (p':ps')) : ss)
@@ -1087,10 +1100,11 @@ createCaption paraElements = do
10871100-- Largely lifted from inlineToOpenXML' in T.P.W.Docx. Can't be easily
10881101-- abstracted because of some different namespaces and monads. TODO.
10891102makePicElement :: PandocMonad m
1090− => MediaInfo
1103+ => PicProps
1104+ -> MediaInfo
10911105 -> Text.Pandoc.Definition.Attr
10921106 -> P m Element
1093−makePicElement mInfo attr = do
1107+makePicElement picProps mInfo attr = do
10941108 opts <- asks envOpts
10951109 pageWidth <- presSizeWidth <$> asks envPresentationSize
10961110 pageHeight <- getPageHeight <$> asks envPresentationSize
@@ -1119,9 +1133,16 @@ makePicElement mInfo attr = do
11191133 let cNvPicPr = mknode "p:cNvPicPr" [] $
11201134 mknode "a:picLocks" [("noGrp","1")
11211135 ,("noChangeAspect","1")] ()
1136+ -- cNvPr will contain the link information so we do that separately,
1137+ -- and register the link if necessary.
1138+ let cNvPrAttr = [("descr", mInfoFilePath mInfo), ("id","0"),("name","Picture 1")]
1139+ cNvPr <- case picPropLink picProps of
1140+ Just link -> do idNum <- registerLink link
1141+ return $ mknode "p:cNvPr" cNvPrAttr $
1142+ mknode "a:hlinkClick" [("r:id", "rId" ++ show idNum)] ()
1143+ Nothing -> return $ mknode "p:cNvPr" cNvPrAttr ()
11221144 let nvPicPr = mknode "p:nvPicPr" []
1123− [ mknode "p:cNvPr"
1124− [("descr", mInfoFilePath mInfo),("id","0"),("name","Picture 1")] ()
1145+ [ cNvPr
11251146 , cNvPicPr
11261147 , mknode "p:nvPr" [] ()]
11271148 let blipFill = mknode "p:blipFill" []
@@ -1267,10 +1288,10 @@ shapeToElement layout (TextBox paras)
12671288 -- XXX: TODO
12681289 | otherwise = return $ mknode "p:sp" [] ()
12691290-- XXX: TODO
1270−shapeToElement layout (Pic fp attr alt) = do
1291+shapeToElement layout (Pic picProps fp attr alt) = do
12711292 mInfo <- registerMedia fp alt
12721293 case mInfoExt mInfo of
1273− Just _ -> makePicElement mInfo attr
1294+ Just _ -> makePicElement picProps mInfo attr
12741295 Nothing -> shapeToElement layout $ TextBox [Paragraph def alt]
12751296shapeToElement _ (GraphicFrame tbls _) = do
12761297 elements <- mapM graphicToElement tbls
@@ -1291,7 +1312,7 @@ shapeToElement _ (GraphicFrame tbls _) = do
12911312shapeToElements :: PandocMonad m => Element -> Shape -> P m [Element]
12921313shapeToElements layout shp = do
12931314 case shp of
1294− (Pic _ _ alt) | (not . null) alt -> do
1315+ (Pic _ _ _ alt) | (not . null) alt -> do
12951316 element <- shapeToElement layout shp
12961317 caption <- createCaption alt
12971318 return [element, caption]