git.iko.soy/typeable/pandoc
on master help sign in
Docx reader: add handling of vml image objects (jgm#4735) (#7257)

They represent images, the same way as other images in vml format.

commitb6a65445e10d74dfe384763c37438338bd395372 authormbrackeantidot <65160241+mbrackeantidot@users.noreply.github.com> dateThu 29 Apr 2021, 18:11 (6 years ago) parentd14c5f9
4 files changed+15−2
src/Text/Pandoc/Readers/Docx/Parse.hs+9−2 test/Tests/Readers/Docx.hs+4 test/docx/image_vml_as_object.docx test/docx/image_vml_as_object.native+2
src/Text/Pandoc/Readers/Docx/Parse.hs+9−2
@@ -709,7 +709,8 @@ elemToParPart ns element
709709 case drawing of
710710 Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp title alt bs $ elemToExtent drawingElem)
711711 Nothing -> throwError WrongElem
712−-- The below is an attempt to deal with images in deprecated vml format.
712+-- The two cases below are an attempt to deal with images in deprecated vml format.
713+-- Todo: check out title and attr for deprecated format.
713714elemToParPart ns element
714715 | isElem ns "w" "r" element
715716 , Just _ <- findChildByName ns "w" "pict" element =
@@ -717,9 +718,15 @@ elemToParPart ns element
717718 >>= findAttrByName ns "r" "id"
718719 in
719720 case drawing of
720− -- Todo: check out title and attr for deprecated format.
721721 Just s -> expandDrawingId s >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
722722 Nothing -> throwError WrongElem
723+elemToParPart ns element
724+ | isElem ns "w" "r" element
725+ , Just objectElem <- findChildByName ns "w" "object" element
726+ , Just shapeElem <- findChildByName ns "v" "shape" objectElem
727+ , Just imagedataElem <- findChildByName ns "v" "imagedata" shapeElem
728+ , Just drawingId <- findAttrByName ns "r" "id" imagedataElem
729+ = expandDrawingId drawingId >>= (\(fp, bs) -> return $ Drawing fp "" "" bs Nothing)
723730-- Chart
724731elemToParPart ns element
725732 | isElem ns "w" "r" element
test/Tests/Readers/Docx.hs+4
@@ -155,6 +155,10 @@ tests = [ testGroup "document"
155155 "VML image"
156156 "docx/image_vml.docx"
157157 "docx/image_vml.native"
158+ , testCompare
159+ "VML image as object"
160+ "docx/image_vml_as_object.docx"
161+ "docx/image_vml_as_object.native"
158162 , testCompare
159163 "inline image in links"
160164 "docx/inline_images.docx"
test/docx/image_vml_as_object.docxnew file

Binary file not shown.

test/docx/image_vml_as_object.nativenew file+2
@@ -0,0 +1,2 @@
1+[Para [Str "Test",Space,Str "with",Space,Str "object",Space,Str "as",Space,Str "image:"]
2+,Para [Image ("",[],[]) [] ("media/image1.emf","")]]