git.iko.soy/typeable/pandoc
on master help sign in
Implemented `\graphicspath` in LaTeX reader.
0448b7dJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+8−1
@@ -53,7 +53,7 @@ import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
53import Text.Pandoc.ImageSize (numUnit, showFl)
53import Text.Pandoc.ImageSize (numUnit, showFl)
54import Control.Monad.Except (throwError)
54import Control.Monad.Except (throwError)
55import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, report,
55import Text.Pandoc.Class (PandocMonad, PandocPure, lookupEnv, report,
56− readFileFromDirs)
56+ readFileFromDirs, setResourcePath)
57
57
58-- | Parse LaTeX from string and return 'Pandoc' document.
58-- | Parse LaTeX from string and return 'Pandoc' document.
59readLaTeX :: PandocMonad m
59readLaTeX :: PandocMonad m
@@ -372,6 +372,7 @@ blockCommands = M.fromList $
372 addMeta "bibliography" . splitBibs))
372 addMeta "bibliography" . splitBibs))
373 -- includes
373 -- includes
374 , ("lstinputlisting", inputListing)
374 , ("lstinputlisting", inputListing)
375+ , ("graphicspath", graphicsPath)
375 ] ++ map ignoreBlocks
376 ] ++ map ignoreBlocks
376 -- these commands will be ignored unless --parse-raw is specified,
377 -- these commands will be ignored unless --parse-raw is specified,
377 -- in which case they will appear as raw latex blocks
378 -- in which case they will appear as raw latex blocks
@@ -390,6 +391,12 @@ blockCommands = M.fromList $
390 , "newpage"
391 , "newpage"
391 ]
392 ]
392
393
394+graphicsPath :: PandocMonad m => LP m Blocks
395+graphicsPath = do
396+ ps <- bgroup *> (manyTill braced egroup)
397+ setResourcePath (".":ps)
398+ return mempty
399+
393addMeta :: PandocMonad m => ToMetaValue a => String -> a -> LP m ()
400addMeta :: PandocMonad m => ToMetaValue a => String -> a -> LP m ()
394addMeta field val = updateState $ \st ->
401addMeta field val = updateState $ \st ->
395 st{ stateMeta = addMetaField field val $ stateMeta st }
402 st{ stateMeta = addMetaField field val $ stateMeta st }
src/Text/Pandoc/Writers/Docx.hs+78−68
@@ -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
71
71
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+ catchError
1178− res <- runExceptT $ lift (P.fetchItem (writerSourceURL opts) src)
1179+ (do (img, mt) <- P.fetchItem (writerSourceURL opts) src
1179− case res of
1180− Left (_ :: PandocError) -> do
1181− report $ CouldNotFetchResource src ""
1182− -- emit alt text
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)
1223+ ,("title", title)
1224+ ,("id","1")
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')
1252+ -- emit alt text
1253+ inlinesToOpenXML opts alt)
1244
1254
1245br :: Element
1255br :: Element
1246br = breakElement "textWrapping"
1256br = breakElement "textWrapping"