git.iko.soy/typeable/pandoc
on master help sign in
Shared: remove 'warn'.

PDF writer: Use 'report' instead of 'warn', make it sensitive to verbosity settings.

commit72af7b4ee5802be3a08566be06acd3d1fa92a51f authorJohn MacFarlane <jgm@berkeley.edu> dateFri 24 Feb 2017, 14:29 (10 years ago) parent887d0b7
3 files changed+17−19
src/Text/Pandoc/Class.hs+1−4 src/Text/Pandoc/PDF.hs+16−10 src/Text/Pandoc/Shared.hs−5
src/Text/Pandoc/Class.hs+1−4
@@ -324,10 +324,7 @@ withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
324324withPaths [] _ fp = throwError $ PandocIOError fp
325325 (userError "file not found in resource path")
326326withPaths (p:ps) action fp =
327− catchError (do res <- action (p </> fp)
328− when (p /= ".") $
329− report $ UsingResourceFrom fp p
330− return res)
327+ catchError (action (p </> fp))
331328 (\_ -> withPaths ps action fp)
332329
333330data PureState = PureState { stStdGen :: StdGen
src/Text/Pandoc/PDF.hs+16−10
@@ -50,7 +50,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
5050import Text.Pandoc.Definition
5151import Text.Pandoc.MediaBag
5252import Text.Pandoc.Walk (walkM)
53−import Text.Pandoc.Shared (warn, withTempDir, inDirectory, stringify)
53+import Text.Pandoc.Shared (withTempDir, inDirectory, stringify)
5454import Text.Pandoc.Writers.Shared (getField, metaToJSON)
5555import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
5656import Text.Pandoc.Logging (Verbosity(..))
@@ -62,8 +62,9 @@ import qualified Codec.Picture as JP
6262#ifdef _WINDOWS
6363import Data.List (intercalate)
6464#endif
65−import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem,
65+import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem, report,
6666 setVerbosity, setMediaBag, runIO)
67+import Text.Pandoc.Logging
6768
6869#ifdef _WINDOWS
6970changePathSeparators :: FilePath -> FilePath
@@ -124,7 +125,7 @@ handleImages :: Verbosity
124125 -> Pandoc -- ^ document
125126 -> IO Pandoc
126127handleImages verbosity opts mediabag tmpdir =
127− walkM (convertImages tmpdir) <=<
128+ walkM (convertImages verbosity tmpdir) <=<
128129 walkM (handleImage' verbosity opts mediabag tmpdir)
129130
130131handleImage' :: Verbosity
@@ -151,20 +152,26 @@ handleImage' verbosity opts mediabag tmpdir (Image attr ils (src,tit)) = do
151152 BS.writeFile fname contents
152153 return $ Image attr ils (fname,tit)
153154 _ -> do
154− warn $ "Could not find image `" ++ src ++ "', skipping..."
155+ runIO $ do
156+ setVerbosity verbosity
157+ report $ CouldNotFetchResource src "skipping..."
155158 -- return alt text
156159 return $ Emph ils
157160handleImage' _ _ _ _ x = return x
158161
159−convertImages :: FilePath -> Inline -> IO Inline
160−convertImages tmpdir (Image attr ils (src, tit)) = do
162+convertImages :: Verbosity -> FilePath -> Inline -> IO Inline
163+convertImages verbosity tmpdir (Image attr ils (src, tit)) = do
161164 img <- convertImage tmpdir src
162165 newPath <-
163166 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
165172 Right fp -> return fp
166173 return (Image attr ils (newPath, tit))
167−convertImages _ x = return x
174+convertImages _ _ x = return x
168175
169176-- Convert formats which do not work well in pdf to png
170177convertImage :: FilePath -> FilePath -> IO (Either String FilePath)
@@ -175,8 +182,7 @@ convertImage tmpdir fname =
175182 Just "application/pdf" -> doNothing
176183 _ -> JP.readImage fname >>= \res ->
177184 case res of
178− Left _ -> return $ Left $ "Unable to convert `" ++
179− fname ++ "' for use with pdflatex."
185+ Left e -> return $ Left e
180186 Right img ->
181187 E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
182188 \(e :: E.SomeException) -> return (Left (show e))
src/Text/Pandoc/Shared.hs−5
@@ -84,7 +84,6 @@ module Text.Pandoc.Shared (
8484 filteredFilesFromArchive,
8585 -- * Error handling
8686 err,
87− warn,
8887 mapLeft,
8988 -- * for squashing blocks
9089 blocksToInlines,
@@ -784,10 +783,6 @@ err exitCode msg = liftIO $ do
784783 exitWith $ ExitFailure exitCode
785784 return undefined
786785
787−warn :: MonadIO m => String -> m ()
788−warn msg = liftIO $ do
789− UTF8.hPutStrLn stderr $ "[warning] " ++ msg
790−
791786mapLeft :: (a -> b) -> Either a c -> Either b c
792787mapLeft f (Left x) = Left (f x)
793788mapLeft _ (Right x) = Right x