From 180d2b5a025362f7fdf20c68a8bc595e0938cb86 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Tue, 3 Sep 2024 22:19:04 -0700 Subject: [PATCH] RTF reader: handle images inside shp contexts. We look for the `pib` property and parse image data inside its value. Closes #10145. --- src/Text/Pandoc/Readers/RTF.hs | 11 +++++++++++ test/command/10145.md | 24 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 test/command/10145.md diff --git a/src/Text/Pandoc/Readers/RTF.hs b/src/Text/Pandoc/Readers/RTF.hs index 4426ab45dc50..7e1a779d0cde 100644 --- a/src/Text/Pandoc/Readers/RTF.hs +++ b/src/Text/Pandoc/Readers/RTF.hs @@ -431,9 +431,20 @@ processTok bs (Tok pos tok') = do Grouped (Tok _ (ControlSymbol '*') : toks@(firsttok:_)) -> case firsttok of Tok _ (ControlWord "shppict" _) -> inGroup (foldM processTok bs toks) + Tok _ (ControlWord "shpinst" _) -> inGroup (foldM processTok bs toks) _ -> bs <$ (do oldTextContent <- sTextContent <$> getState processTok mempty (Tok pos (Grouped toks)) updateState $ \st -> st{ sTextContent = oldTextContent }) + Grouped (Tok _ (ControlWord "shp" _) : toks) -> + inGroup (foldM processTok bs toks) + Grouped [ Tok _ (ControlWord "sp" _) + , Tok _ (Grouped [Tok _ (ControlWord "sn" _), + Tok _ (UnformattedText sn)]) + , Tok _ (Grouped (Tok _ (ControlWord "sv" _) : svtoks)) + ] -> + case sn of + "pib" -> inGroup (foldM processTok bs svtoks) + _ -> pure bs Grouped (Tok _ (ControlWord "fonttbl" _) : toks) -> inGroup $ do updateState $ \s -> s{ sFontTable = processFontTable toks } pure bs diff --git a/test/command/10145.md b/test/command/10145.md new file mode 100644 index 000000000000..de063aa621d6 --- /dev/null +++ b/test/command/10145.md @@ -0,0 +1,24 @@ +``` +% pandoc -f rtf -t native +{\rtf1\ansi\deff0{\fonttbl{\f0 \fswiss Helvetica;}{\f1 \fmodern Courier;}} +{\colortbl;\red255\green0\blue0;\red0\green0\blue255;} +\widowctrl\hyphauto + +{\pard \ql \f0 \sa0 \li0 \fi0 {\shp{\*\shpinst\shpwr2\shpwrk3\shpbypara\shpbyignore\shptop1320\shpbottom7745\shpbxcolumn\shpbxignore\shpleft0\shpright9638{\sp{\sn shapeType}{\sv 75}}{\sp{\sn wzDescription}{\sv }}{\sp{\sn wzName}{\sv }}{\sp{\sn pib}{\sv {\pict\jpegblip\picw20\pich22\picwgoal400\pichgoal440 ffd8ffe000104a46494600010101004800480000fffe0050546869732061727420697320696e20746865207075626c696320646f6d61696e2e204b6576696e204875676865732c206b6576696e68406569742e636f6d2c2053657074656d6265722031393935ffdb00430001010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffdb00430101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101ffc00011080016001403012200021101031101ffc4001a000100020301000000000000000000000000080905060a07ffc400231000010501000300010500000000000000060304050708020001090a11153976b7ffc400160101010100000000000000000000000000060800ffc400261101000102050109000000000000000000010200030405061121b33134365154717475b4ffda000c03010002110311003f00a90cf388f366a62aa720ed6ae07f96901f3831d973452b8cf36fe3570fc908e46d466433e5dd954f2e96992d9e498c7753faa44916e016ca91cc7d88b38fe60a5b97737defcbcc539c98d336a57f4fc2ca9a486bf07ab575ad9a3af4df221d8215e36df86c4504ff0024574551b3d687ee0575757b3ad64e311ee62bd94158d37e24198c43973099f1fc0c41614d950246513a081abf76cfe7061f6863281e6352fd1670949c148dd6dfb0d25f5b3689b1d5c965b0eacbf4e0932ad28e22ab9ae945633f4744bd3c8cee0a7fdf085b9000f449c5f7afa30b83e0b6fd7b0c8429c9467ff9715347c891e25fa24a205861aa715e6a09bd0488237dc2723414d9891381524e8ca7c0894664f835653631ab55ee7e3de433e4ff001b30949124e4c10c8b6ad0a479b3f9c937b2cf5bc0095ad600a0a41a0e9faee174a1c605e161c6c7a313539650b0113190f1a8368e60d5b24f30ff008ea7f0bf867fa6595feeb6978f1fe0f9c26177f4d63a51a9235184750e7d18811339cd000000c75f000e00380380ae390c350def826ed42ad051fa6f501c50f9b699c3b69cbeb76476d202bf3ac985b6e0e968be66572893e6a744540bd9722e5c87956848629bc2559306bd113e8653d3b6aff651dfad7a3ac8b02958cba02a93ccf525757039bae6cff090e1d90688e8aa233ee86a4c4a3e0586d6b2340522e47dcb7d0046d8a5acb05a123ee25d2b230b2ada6e2e2f9ede3c05202520ec2487b0d56562529d8b3393bca76adca4ec1bca508abb001babc007915d84fe3dd14e207e3c62f8379da2a3b861fb6629d28dba53b6ea388ebfed866bf6dfb553455e91ed547ae92e9445253a4fdf3efb4f8ebdfbe7d3c78f1ee0bb9e13e358e942a4ed49e22cff00eeb35fdd7ebfffd9}}}}}\par} +{\pard \ql \f0 \sa0 \li0 \fi0 moon\par} +} +^D +[ Para + [ Image + ( "" + , [] + , [ ( "width" , "0.2777777777777778in" ) + , ( "height" , "0.3055555555555556in" ) + ] + ) + [ Str "image" ] + ( "9ea9761885249909bcd8a610706eef51b54dc351.jpg" , "" ) + ] +, Para [ Str "moon" ] +] +```