git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: Be more specific in parsing images

We not only want "w:drawing", because that could also include charts. Now we specify "w:drawing"//"pic:pic". This shouldn't change behavior at all, but it's a first step toward allowing other sorts of drawing data as well.

commit7539de02873aa1095a3648e88fb9f5adda86c8fb authorJesse Rosenthal <jrosenthal@jhu.edu> dateThu 10 Nov 2016, 13:00 (10 years ago) parent7e5220b
1 file changed+10−6
src/Text/Pandoc/Readers/Docx/Parse.hs+10−6
src/Text/Pandoc/Readers/Docx/Parse.hs+10−6
@@ -660,10 +660,12 @@ getTitleAndAlt ns element =
660660elemToParPart :: NameSpaces -> Element -> D ParPart
661661elemToParPart ns element
662662 | isElem ns "w" "r" element
663− , Just drawingElem <- findChild (elemName ns "w" "drawing") element =
664− let (title, alt) = getTitleAndAlt ns drawingElem
663+ , Just drawingElem <- findChild (elemName ns "w" "drawing") element
664+ , pic_ns <- "http://schemas.openxmlformats.org/drawingml/2006/picture"
665+ , Just picElem <- findElement (QName "pic" (Just pic_ns) (Just "pic")) drawingElem
666+ = let (title, alt) = getTitleAndAlt ns drawingElem
665667 a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
666− drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
668+ drawing = findElement (QName "blip" (Just a_ns) (Just "a")) picElem
667669 >>= findAttr (elemName ns "r" "embed")
668670 in
669671 case drawing of
@@ -764,10 +766,12 @@ elemToExtent drawingElem =
764766
765767childElemToRun :: NameSpaces -> Element -> D Run
766768childElemToRun ns element
767− | isElem ns "w" "drawing" element =
768− let (title, alt) = getTitleAndAlt ns element
769+ | isElem ns "w" "drawing" element
770+ , pic_ns <- "http://schemas.openxmlformats.org/drawingml/2006/picture"
771+ , Just picElem <- findElement (QName "pic" (Just pic_ns) (Just "pic")) element
772+ = let (title, alt) = getTitleAndAlt ns element
769773 a_ns = "http://schemas.openxmlformats.org/drawingml/2006/main"
770− drawing = findElement (QName "blip" (Just a_ns) (Just "a")) element
774+ drawing = findElement (QName "blip" (Just a_ns) (Just "a")) picElem
771775 >>= findAttr (QName "embed" (lookup "r" ns) (Just "r"))
772776 in
773777 case drawing of