@@ -48,14 +48,13 @@ import Text.Pandoc.Options
48import Text.Pandoc.Writers.Math
48import Text.Pandoc.Writers.Math
49import Text.Pandoc.Highlighting ( highlight )
49import Text.Pandoc.Highlighting ( highlight )
50import Text.Pandoc.Walk
50import Text.Pandoc.Walk
51−import Text.Pandoc.Error (PandocError)
52import Text.XML.Light as XML
51import Text.XML.Light as XML
53import Text.TeXMath
52import Text.TeXMath
54import Text.Pandoc.Readers.Docx.StyleMap
53import Text.Pandoc.Readers.Docx.StyleMap
55import Control.Monad.Reader
54import Control.Monad.Reader
56import Control.Monad.State
55import Control.Monad.State
57import Skylighting
56import Skylighting
58−import Control.Monad.Except (runExceptT)
57+import Control.Monad.Except (catchError)
59import System.Random (randomR)
58import System.Random (randomR)
60import Text.Printf (printf)
59import Text.Printf (printf)
61import Data.Monoid ((<>))
60import Data.Monoid ((<>))
@@ -68,6 +67,7 @@ import Data.Char (ord, isSpace, toLower)
68import Text.Pandoc.Class (PandocMonad, report)
67import Text.Pandoc.Class (PandocMonad, report)
69import qualified Text.Pandoc.Class as P
68import qualified Text.Pandoc.Class as P
70import Text.Pandoc.Logging
69import Text.Pandoc.Logging
70+import Text.Pandoc.Error
72data ListMarker = NoMarker
72data ListMarker = NoMarker
73 | BulletMarker
73 | BulletMarker
@@ -1175,72 +1175,82 @@ inlineToOpenXML' opts (Image attr alt (src, title)) = do
1175 case M.lookup src imgs of
1175 case M.lookup src imgs of
1176 Just (_,_,_,elt,_) -> return [elt]
1176 Just (_,_,_,elt,_) -> return [elt]
1177 Nothing -> do
1177 Nothing -> do
1178− res <- runExceptT $ lift (P.fetchItem (writerSourceURL opts) src)
1179+ (do (img, mt) <- P.fetchItem (writerSourceURL opts) src
1180− Left (_ :: PandocError) -> do
1181− report $ CouldNotFetchResource src ""
1183− inlinesToOpenXML opts alt
1184− Right (img, mt) -> do
1185− ident <- ("rId"++) `fmap` ((lift . lift) getUniqueId)
1180+ ident <- ("rId"++) `fmap` ((lift . lift) getUniqueId)
1186− let (xpt,ypt) = desiredSizeInPoints opts attr
1181+ let (xpt,ypt) = desiredSizeInPoints opts attr
1187− (either (const def) id (imageSize opts img))
1182+ (either (const def) id (imageSize opts img))
1188− -- 12700 emu = 1 pt
1183+ -- 12700 emu = 1 pt
1189− let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700) (pageWidth * 12700)
1184+ let (xemu,yemu) = fitToPage (xpt * 12700, ypt * 12700)
1185+ (pageWidth * 12700)
1190− let cNvPicPr = mknode "pic:cNvPicPr" [] $
1186+ let cNvPicPr = mknode "pic:cNvPicPr" [] $
1191− mknode "a:picLocks" [("noChangeArrowheads","1"),("noChangeAspect","1")] ()
1187+ mknode "a:picLocks" [("noChangeArrowheads","1")
1188+ ,("noChangeAspect","1")] ()
1192− let nvPicPr = mknode "pic:nvPicPr" []
1189+ let nvPicPr = mknode "pic:nvPicPr" []
1193− [ mknode "pic:cNvPr"
1190+ [ mknode "pic:cNvPr"
1194− [("descr",src),("id","0"),("name","Picture")] ()
1191+ [("descr",src),("id","0"),("name","Picture")] ()
1195− , cNvPicPr ]
1192+ , cNvPicPr ]
1196− let blipFill = mknode "pic:blipFill" []
1193+ let blipFill = mknode "pic:blipFill" []
1197− [ mknode "a:blip" [("r:embed",ident)] ()
1194+ [ mknode "a:blip" [("r:embed",ident)] ()
1195+ , mknode "a:stretch" [] $
1198− , mknode "a:stretch" [] $ mknode "a:fillRect" [] () ]
1196+ mknode "a:fillRect" [] () ]
1199− let xfrm = mknode "a:xfrm" []
1197+ let xfrm = mknode "a:xfrm" []
1200− [ mknode "a:off" [("x","0"),("y","0")] ()
1198+ [ mknode "a:off" [("x","0"),("y","0")] ()
1201− , mknode "a:ext" [("cx",show xemu),("cy",show yemu)] () ]
1199+ , mknode "a:ext" [("cx",show xemu)
1200+ ,("cy",show yemu)] () ]
1202− let prstGeom = mknode "a:prstGeom" [("prst","rect")] $
1201+ let prstGeom = mknode "a:prstGeom" [("prst","rect")] $
1203− mknode "a:avLst" [] ()
1202+ mknode "a:avLst" [] ()
1204− let ln = mknode "a:ln" [("w","9525")]
1203+ let ln = mknode "a:ln" [("w","9525")]
1205− [ mknode "a:noFill" [] ()
1204+ [ mknode "a:noFill" [] ()
1206− , mknode "a:headEnd" [] ()
1205+ , mknode "a:headEnd" [] ()
1207− , mknode "a:tailEnd" [] () ]
1206+ , mknode "a:tailEnd" [] () ]
1208− let spPr = mknode "pic:spPr" [("bwMode","auto")]
1207+ let spPr = mknode "pic:spPr" [("bwMode","auto")]
1209− [xfrm, prstGeom, mknode "a:noFill" [] (), ln]
1208+ [xfrm, prstGeom, mknode "a:noFill" [] (), ln]
1210− let graphic = mknode "a:graphic" [] $
1209+ let graphic = mknode "a:graphic" [] $
1210+ mknode "a:graphicData"
1211− mknode "a:graphicData" [("uri","http://schemas.openxmlformats.org/drawingml/2006/picture")]
1211+ [("uri","http://schemas.openxmlformats.org/drawingml/2006/picture")]
1212− [ mknode "pic:pic" []
1212+ [ mknode "pic:pic" []
1213− [ nvPicPr
1213+ [ nvPicPr
1214− , blipFill
1214+ , blipFill
1215− , spPr ] ]
1215+ , spPr ] ]
1216− let imgElt = mknode "w:r" [] $
1216+ let imgElt = mknode "w:r" [] $
1217− mknode "w:drawing" [] $
1217+ mknode "w:drawing" [] $
1218− mknode "wp:inline" []
1218+ mknode "wp:inline" []
1219− [ mknode "wp:extent" [("cx",show xemu),("cy",show yemu)] ()
1219+ [ mknode "wp:extent" [("cx",show xemu),("cy",show yemu)] ()
1220− , mknode "wp:effectExtent" [("b","0"),("l","0"),("r","0"),("t","0")] ()
1220+ , mknode "wp:effectExtent"
1221+ [("b","0"),("l","0"),("r","0"),("t","0")] ()
1221− , mknode "wp:docPr" [("descr",stringify alt), ("title", title), ("id","1"),("name","Picture")] ()
1222+ , mknode "wp:docPr" [("descr",stringify alt)
1225+ ,("name","Picture")] ()
1222− , graphic ]
1226+ , graphic ]
1223− let imgext = case mt >>= extensionFromMimeType of
1227+ let imgext = case mt >>= extensionFromMimeType of
1224− Just x -> '.':x
1228+ Just x -> '.':x
1225− Nothing -> case imageType img of
1229+ Nothing -> case imageType img of
1226− Just Png -> ".png"
1230+ Just Png -> ".png"
1227− Just Jpeg -> ".jpeg"
1231+ Just Jpeg -> ".jpeg"
1228− Just Gif -> ".gif"
1232+ Just Gif -> ".gif"
1229− Just Pdf -> ".pdf"
1233+ Just Pdf -> ".pdf"
1230− Just Eps -> ".eps"
1234+ Just Eps -> ".eps"
1231− Just Svg -> ".svg"
1235+ Just Svg -> ".svg"
1232− Nothing -> ""
1236+ Nothing -> ""
1233− if null imgext
1237+ if null imgext
1234− then -- without an extension there is no rule for content type
1238+ then -- without an extension there is no rule for content type
1235− inlinesToOpenXML opts alt -- return alt to avoid corrupted docx
1239+ inlinesToOpenXML opts alt -- return alt to avoid corrupted docx
1236− else do
1240+ else do
1237− let imgpath = "media/" ++ ident ++ imgext
1241+ let imgpath = "media/" ++ ident ++ imgext
1238− let mbMimeType = mt <|> getMimeType imgpath
1242+ let mbMimeType = mt <|> getMimeType imgpath
1239− -- insert mime type to use in constructing [Content_Types].xml
1243+ -- insert mime type to use in constructing [Content_Types].xml
1240− modify $ \st -> st{ stImages =
1244+ modify $ \st -> st{ stImages =
1241− M.insert src (ident, imgpath, mbMimeType, imgElt, img)
1245+ M.insert src (ident, imgpath, mbMimeType, imgElt, img)
1242− $ stImages st }
1246+ $ stImages st }
1243− return [imgElt]
1247+ return [imgElt])
1248+ (\e -> do case e of
1249+ PandocIOError _ e' ->
1250+ report $ CouldNotFetchResource src (show e')
1251+ e' -> report $ CouldNotFetchResource src (show e')
1253+ inlinesToOpenXML opts alt)
1245br :: Element
1255br :: Element
1246br = breakElement "textWrapping"
1256br = breakElement "textWrapping"