git.iko.soy/typeable/pandoc
on master help sign in
Shared: remove 'warn'.
72af7b4John MacFarlane
src/Text/Pandoc/Class.hs+1−4
@@ -324,10 +324,7 @@ withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
324withPaths [] _ fp = throwError $ PandocIOError fp
324withPaths [] _ fp = throwError $ PandocIOError fp
325 (userError "file not found in resource path")
325 (userError "file not found in resource path")
326withPaths (p:ps) action fp =
326withPaths (p:ps) action fp =
327− catchError (do res <- action (p </> fp)
327+ catchError (action (p </> fp))
328− when (p /= ".") $
329− report $ UsingResourceFrom fp p
330− return res)
331 (\_ -> withPaths ps action fp)
328 (\_ -> withPaths ps action fp)
332
329
333data PureState = PureState { stStdGen :: StdGen
330data PureState = PureState { stStdGen :: StdGen
src/Text/Pandoc/PDF.hs+16−10
@@ -50,7 +50,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
50import Text.Pandoc.Definition
50import Text.Pandoc.Definition
51import Text.Pandoc.MediaBag
51import Text.Pandoc.MediaBag
52import Text.Pandoc.Walk (walkM)
52import Text.Pandoc.Walk (walkM)
53−import Text.Pandoc.Shared (warn, withTempDir, inDirectory, stringify)
53+import Text.Pandoc.Shared (withTempDir, inDirectory, stringify)
54import Text.Pandoc.Writers.Shared (getField, metaToJSON)
54import Text.Pandoc.Writers.Shared (getField, metaToJSON)
55import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
55import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
56import Text.Pandoc.Logging (Verbosity(..))
56import Text.Pandoc.Logging (Verbosity(..))
@@ -62,8 +62,9 @@ import qualified Codec.Picture as JP
62#ifdef _WINDOWS
62#ifdef _WINDOWS
63import Data.List (intercalate)
63import Data.List (intercalate)
64#endif
64#endif
65−import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem,
65+import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem, report,
66 setVerbosity, setMediaBag, runIO)
66 setVerbosity, setMediaBag, runIO)
67+import Text.Pandoc.Logging
67
68
68#ifdef _WINDOWS
69#ifdef _WINDOWS
69changePathSeparators :: FilePath -> FilePath
70changePathSeparators :: FilePath -> FilePath
@@ -124,7 +125,7 @@ handleImages :: Verbosity
124 -> Pandoc -- ^ document
125 -> Pandoc -- ^ document
125 -> IO Pandoc
126 -> IO Pandoc
126handleImages verbosity opts mediabag tmpdir =
127handleImages verbosity opts mediabag tmpdir =
127− walkM (convertImages tmpdir) <=<
128+ walkM (convertImages verbosity tmpdir) <=<
128 walkM (handleImage' verbosity opts mediabag tmpdir)
129 walkM (handleImage' verbosity opts mediabag tmpdir)
129
130
130handleImage' :: Verbosity
131handleImage' :: Verbosity
@@ -151,20 +152,26 @@ handleImage' verbosity opts mediabag tmpdir (Image attr ils (src,tit)) = do
151 BS.writeFile fname contents
152 BS.writeFile fname contents
152 return $ Image attr ils (fname,tit)
153 return $ Image attr ils (fname,tit)
153 _ -> do
154 _ -> do
154− warn $ "Could not find image `" ++ src ++ "', skipping..."
155+ runIO $ do
156+ setVerbosity verbosity
157+ report $ CouldNotFetchResource src "skipping..."
155 -- return alt text
158 -- return alt text
156 return $ Emph ils
159 return $ Emph ils
157handleImage' _ _ _ _ x = return x
160handleImage' _ _ _ _ x = return x
158
161
159−convertImages :: FilePath -> Inline -> IO Inline
162+convertImages :: Verbosity -> FilePath -> Inline -> IO Inline
160−convertImages tmpdir (Image attr ils (src, tit)) = do
163+convertImages verbosity tmpdir (Image attr ils (src, tit)) = do
161 img <- convertImage tmpdir src
164 img <- convertImage tmpdir src
162 newPath <-
165 newPath <-
163 case img of
166 case img of
164− Left e -> src <$ warn e
167+ Left e -> do
168+ runIO $ do
169+ setVerbosity verbosity
170+ report $ CouldNotConvertImage src e
171+ return src
165 Right fp -> return fp
172 Right fp -> return fp
166 return (Image attr ils (newPath, tit))
173 return (Image attr ils (newPath, tit))
167−convertImages _ x = return x
174+convertImages _ _ x = return x
168
175
169-- Convert formats which do not work well in pdf to png
176-- Convert formats which do not work well in pdf to png
170convertImage :: FilePath -> FilePath -> IO (Either String FilePath)
177convertImage :: FilePath -> FilePath -> IO (Either String FilePath)
@@ -175,8 +182,7 @@ convertImage tmpdir fname =
175 Just "application/pdf" -> doNothing
182 Just "application/pdf" -> doNothing
176 _ -> JP.readImage fname >>= \res ->
183 _ -> JP.readImage fname >>= \res ->
177 case res of
184 case res of
178− Left _ -> return $ Left $ "Unable to convert `" ++
185+ Left e -> return $ Left e
179− fname ++ "' for use with pdflatex."
180 Right img ->
186 Right img ->
181 E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
187 E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
182 \(e :: E.SomeException) -> return (Left (show e))
188 \(e :: E.SomeException) -> return (Left (show e))
src/Text/Pandoc/Shared.hs−5
@@ -84,7 +84,6 @@ module Text.Pandoc.Shared (
84 filteredFilesFromArchive,
84 filteredFilesFromArchive,
85 -- * Error handling
85 -- * Error handling
86 err,
86 err,
87− warn,
88 mapLeft,
87 mapLeft,
89 -- * for squashing blocks
88 -- * for squashing blocks
90 blocksToInlines,
89 blocksToInlines,
@@ -784,10 +783,6 @@ err exitCode msg = liftIO $ do
784 exitWith $ ExitFailure exitCode
783 exitWith $ ExitFailure exitCode
785 return undefined
784 return undefined
786
785
787−warn :: MonadIO m => String -> m ()
788−warn msg = liftIO $ do
789− UTF8.hPutStrLn stderr $ "[warning] " ++ msg
790−
791mapLeft :: (a -> b) -> Either a c -> Either b c
786mapLeft :: (a -> b) -> Either a c -> Either b c
792mapLeft f (Left x) = Left (f x)
787mapLeft f (Left x) = Left (f x)
793mapLeft _ (Right x) = Right x
788mapLeft _ (Right x) = Right x