summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2023-07-14 13:14:05 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2023-07-14 13:14:05 -0700
commitc6ac1749ee9a92a7cbd1486a247ba4bae6ae8309 (patch)
tree05c99102795c82850e0cf5f7b2d8d413ac739466
parenta97b270b28b0f7e7d62f2738bd38e10f484ebe09 (diff)
Docx reader: use SVG version of image if present.
Previously the backup PNG was exported even if an SVG was present, but the SVG should be preferred. Closes #7244.
-rw-r--r--src/Text/Pandoc/Readers/Docx/Parse.hs18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/Docx/Parse.hs b/src/Text/Pandoc/Readers/Docx/Parse.hs
index 3f02a6abb..aebc4a5d4 100644
--- a/src/Text/Pandoc/Readers/Docx/Parse.hs
+++ b/src/Text/Pandoc/Readers/Docx/Parse.hs
@@ -915,10 +915,9 @@ elemToParPart' ns element
, pic_ns <- "http://schemas.openxmlformats.org/drawingml/2006/picture"
, picElems <- findElements (QName "pic" (Just pic_ns) (Just "pic")) drawingElem
= let (title, alt) = getTitleAndAlt ns drawingElem
- a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
drawings = map (\el ->
- ((findElement (QName "blip" (Just a_ns) (Just "a")) el
- >>= findAttrByName ns "r" "embed"), el)) picElems
+ ((findBlip el >>= findAttrByName ns "r" "embed"), el))
+ picElems
in mapM (\case
(Just s, el) -> do
(fp, bs) <- expandDrawingId s
@@ -1040,10 +1039,9 @@ childElemToRun ns element
, pic_ns <- "http://schemas.openxmlformats.org/drawingml/2006/picture"
, picElems <- findElements (QName "pic" (Just pic_ns) (Just "pic")) element
= let (title, alt) = getTitleAndAlt ns element
- a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
drawings = map (\el ->
- ((findElement (QName "blip" (Just a_ns) (Just "a")) el
- >>= findAttrByName ns "r" "embed"), el)) picElems
+ ((findBlip el >>= findAttrByName ns "r" "embed"), el))
+ picElems
in mapM (\case
(Just s, el) -> do
(fp, bs) <- expandDrawingId s
@@ -1236,3 +1234,11 @@ elemToRunElems _ _ = throwError WrongElem
setFont :: Maybe Font -> ReaderEnv -> ReaderEnv
setFont f s = s{envFont = f}
+
+findBlip :: Element -> Maybe Element
+findBlip el = do
+ blip <- findElement (QName "blip" (Just a_ns) (Just "a")) el
+ -- return svg if present:
+ filterElementName (\(QName tag _ _) -> tag == "svgBlip") el `mplus` pure blip
+ where
+ a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"