@@ -76,7 +76,7 @@ import System.Posix.Terminal (queryTerminal)
7676import System.Posix.IO (stdOutput)
7777#endif
7878import Control.Monad.Trans
79−import Text.Pandoc.Class (withMediaBag, PandocIO, withWarningsToStderr)
79+import Text.Pandoc.Class (withMediaBag, PandocIO, getWarnings)
8080
8181type Transform = Pandoc -> Pandoc
8282
@@ -197,6 +197,7 @@ data Opt = Opt
197197 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
198198 , optVerbose :: Bool -- ^ Verbose diagnostic output
199199 , optQuiet :: Bool -- ^ Suppress warnings
200+ , optFailIfWarnings :: Bool -- ^ Fail on warnings
200201 , optReferenceLinks :: Bool -- ^ Use reference links in writing markdown, rst
201202 , optReferenceLocation :: ReferenceLocation -- ^ location for footnotes and link references in markdown output
202203 , optDpi :: Int -- ^ Dpi
@@ -263,6 +264,7 @@ defaultOpts = Opt
263264 , optIgnoreArgs = False
264265 , optVerbose = False
265266 , optQuiet = False
267+ , optFailIfWarnings = False
266268 , optReferenceLinks = False
267269 , optReferenceLocation = EndOfDocument
268270 , optDpi = 96
@@ -910,6 +912,11 @@ options =
910912 (\opt -> return opt { optQuiet = True }))
911913 "" -- "Suppress warnings."
912914
915+ , Option "" ["fail-if-warnings"]
916+ (NoArg
917+ (\opt -> return opt { optFailIfWarnings = True }))
918+ "" -- "Exit with error status if there were warnings."
919+
913920 , Option "" ["bash-completion"]
914921 (NoArg
915922 (\_ -> do
@@ -1195,6 +1202,7 @@ convertWithOpts opts args = do
11951202 , optIgnoreArgs = ignoreArgs
11961203 , optVerbose = verbose
11971204 , optQuiet = quiet
1205+ , optFailIfWarnings = failIfWarnings
11981206 , optReferenceLinks = referenceLinks
11991207 , optReferenceLocation = referenceLocation
12001208 , optDpi = dpi
@@ -1409,10 +1417,17 @@ convertWithOpts opts args = do
14091417 then 0
14101418 else tabStop)
14111419
1412− let runIO' = runIOorExplode .
1413− (if quiet
1414− then id
1415− else withWarningsToStderr)
1420+ let runIO' f = do
1421+ (res, warnings) <- runIOorExplode $ do
1422+ x <- f
1423+ ws <- getWarnings
1424+ return (x, ws)
1425+ when (not (null warnings)) $ do
1426+ unless quiet $
1427+ mapM_ warn warnings
1428+ when failIfWarnings $
1429+ err 3 "Failing because there were warnings."
1430+ return res
14161431
14171432 let sourceToDoc :: [FilePath] -> IO (Pandoc, MediaBag)
14181433 sourceToDoc sources' =