fillMediaBag: Keep attributes of original image on Span

Images that cannot be fetched are replaced with a Span that contains the
image's description. The span now also retains all original image
attributes and inherits all attributes of the image. Furthermore, the
classes `image` and `placeholder` are added, and path and title are
store in attributes `original-image-src` and `original-image-title`,
respectively.

Closes: #8099
This commit is contained in:
Albert Krewinkel 2022-06-07 12:38:56 +02:00 committed by John MacFarlane
parent 516c827d61
commit 096863e0ad

View file

@ -703,15 +703,24 @@ fillMediaBag d = walkM handleImage d
report $ CouldNotFetchResource src
"replacing image with description"
-- emit alt text
return $ Span ("",["image"],[]) lab
return $ replacementSpan attr src tit lab
PandocHttpError u er -> do
report $ CouldNotFetchResource u
(T.pack $ show er ++ "\rReplacing image with description.")
-- emit alt text
return $ Span ("",["image"],[]) lab
return $ replacementSpan attr src tit lab
_ -> throwError e)
handleImage x = return x
replacementSpan (ident, classes, attribs) src title descr =
Span ( ident
, "image":"placeholder":classes
, ("original-image-src", src) :
("original-image-title", title) :
attribs
)
descr
-- This requires UndecidableInstances. We could avoid that
-- by repeating the definitions below for every monad transformer
-- we use: ReaderT, WriterT, StateT, RWST. But this seems to