aboutsummaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2017-02-24 14:29:56 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2017-02-24 14:29:56 +0100
commit72af7b4ee5802be3a08566be06acd3d1fa92a51f (patch)
tree820af029ac925d4b113af13bceadb41bdb11f864 /src/Text
parent887d0b70fe3c3fd8919c8ffcf52577ce42b4a92e (diff)
downloadpandoc-72af7b4ee5802be3a08566be06acd3d1fa92a51f.tar.gz
Shared: remove 'warn'.
PDF writer: Use 'report' instead of 'warn', make it sensitive to verbosity settings.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/Class.hs5
-rw-r--r--src/Text/Pandoc/PDF.hs26
-rw-r--r--src/Text/Pandoc/Shared.hs5
3 files changed, 17 insertions, 19 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs
index 432a607db..b053e9063 100644
--- a/src/Text/Pandoc/Class.hs
+++ b/src/Text/Pandoc/Class.hs
@@ -324,10 +324,7 @@ withPaths :: PandocMonad m => [FilePath] -> (FilePath -> m a) -> FilePath -> m a
withPaths [] _ fp = throwError $ PandocIOError fp
(userError "file not found in resource path")
withPaths (p:ps) action fp =
- catchError (do res <- action (p </> fp)
- when (p /= ".") $
- report $ UsingResourceFrom fp p
- return res)
+ catchError (action (p </> fp))
(\_ -> withPaths ps action fp)
data PureState = PureState { stStdGen :: StdGen
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 1265f3f72..35141ae88 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -50,7 +50,7 @@ import qualified Text.Pandoc.UTF8 as UTF8
import Text.Pandoc.Definition
import Text.Pandoc.MediaBag
import Text.Pandoc.Walk (walkM)
-import Text.Pandoc.Shared (warn, withTempDir, inDirectory, stringify)
+import Text.Pandoc.Shared (withTempDir, inDirectory, stringify)
import Text.Pandoc.Writers.Shared (getField, metaToJSON)
import Text.Pandoc.Options (WriterOptions(..), HTMLMathMethod(..))
import Text.Pandoc.Logging (Verbosity(..))
@@ -62,8 +62,9 @@ import qualified Codec.Picture as JP
#ifdef _WINDOWS
import Data.List (intercalate)
#endif
-import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem,
+import Text.Pandoc.Class (PandocIO, runIOorExplode, fetchItem, report,
setVerbosity, setMediaBag, runIO)
+import Text.Pandoc.Logging
#ifdef _WINDOWS
changePathSeparators :: FilePath -> FilePath
@@ -124,7 +125,7 @@ handleImages :: Verbosity
-> Pandoc -- ^ document
-> IO Pandoc
handleImages verbosity opts mediabag tmpdir =
- walkM (convertImages tmpdir) <=<
+ walkM (convertImages verbosity tmpdir) <=<
walkM (handleImage' verbosity opts mediabag tmpdir)
handleImage' :: Verbosity
@@ -151,20 +152,26 @@ handleImage' verbosity opts mediabag tmpdir (Image attr ils (src,tit)) = do
BS.writeFile fname contents
return $ Image attr ils (fname,tit)
_ -> do
- warn $ "Could not find image `" ++ src ++ "', skipping..."
+ runIO $ do
+ setVerbosity verbosity
+ report $ CouldNotFetchResource src "skipping..."
-- return alt text
return $ Emph ils
handleImage' _ _ _ _ x = return x
-convertImages :: FilePath -> Inline -> IO Inline
-convertImages tmpdir (Image attr ils (src, tit)) = do
+convertImages :: Verbosity -> FilePath -> Inline -> IO Inline
+convertImages verbosity tmpdir (Image attr ils (src, tit)) = do
img <- convertImage tmpdir src
newPath <-
case img of
- Left e -> src <$ warn e
+ Left e -> do
+ runIO $ do
+ setVerbosity verbosity
+ report $ CouldNotConvertImage src e
+ return src
Right fp -> return fp
return (Image attr ils (newPath, tit))
-convertImages _ x = return x
+convertImages _ _ x = return x
-- Convert formats which do not work well in pdf to png
convertImage :: FilePath -> FilePath -> IO (Either String FilePath)
@@ -175,8 +182,7 @@ convertImage tmpdir fname =
Just "application/pdf" -> doNothing
_ -> JP.readImage fname >>= \res ->
case res of
- Left _ -> return $ Left $ "Unable to convert `" ++
- fname ++ "' for use with pdflatex."
+ Left e -> return $ Left e
Right img ->
E.catch (Right fileOut <$ JP.savePngImage fileOut img) $
\(e :: E.SomeException) -> return (Left (show e))
diff --git a/src/Text/Pandoc/Shared.hs b/src/Text/Pandoc/Shared.hs
index dbe00d231..19d915b11 100644
--- a/src/Text/Pandoc/Shared.hs
+++ b/src/Text/Pandoc/Shared.hs
@@ -84,7 +84,6 @@ module Text.Pandoc.Shared (
filteredFilesFromArchive,
-- * Error handling
err,
- warn,
mapLeft,
-- * for squashing blocks
blocksToInlines,
@@ -784,10 +783,6 @@ err exitCode msg = liftIO $ do
exitWith $ ExitFailure exitCode
return undefined
-warn :: MonadIO m => String -> m ()
-warn msg = liftIO $ do
- UTF8.hPutStrLn stderr $ "[warning] " ++ msg
-
mapLeft :: (a -> b) -> Either a c -> Either b c
mapLeft f (Left x) = Left (f x)
mapLeft _ (Right x) = Right x