diff options
author | John MacFarlane <jgm@berkeley.edu> | 2016-12-03 16:57:23 +0100 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2017-01-25 17:07:40 +0100 |
commit | 5ab8909661242d992726411d6adc6490eacaafe3 (patch) | |
tree | 969018024ecb3e25b5e7217b0c0b688fbd291f22 /src/Text/Pandoc | |
parent | 29b3975cbec5d393e404f96e5f68506587ee74de (diff) | |
download | pandoc-5ab8909661242d992726411d6adc6490eacaafe3.tar.gz |
New withWarningsToStderr exported from Text.Pandoc.Class.
And use this in pandoc.hs so that messages actually get printed.
Diffstat (limited to 'src/Text/Pandoc')
-rw-r--r-- | src/Text/Pandoc/Class.hs | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/Text/Pandoc/Class.hs b/src/Text/Pandoc/Class.hs index 0881878ed..1059f5324 100644 --- a/src/Text/Pandoc/Class.hs +++ b/src/Text/Pandoc/Class.hs @@ -51,6 +51,7 @@ module Text.Pandoc.Class ( PandocMonad(..) , runIOorExplode , runPure , withMediaBag + , withWarningsToStderr ) where import Prelude hiding (readFile, fail) @@ -64,7 +65,8 @@ import qualified Text.Pandoc.Shared as IO ( fetchItem , fetchItem' , getDefaultReferenceDocx , getDefaultReferenceODT - , readDataFile) + , readDataFile + , warn) import Text.Pandoc.Compat.Time (UTCTime) import Text.Pandoc.Parsing (ParserT, ParserState, SourcePos) import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime) @@ -119,6 +121,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m, MonadState C -- Functions defined for all PandocMonad instances +-- TODO should we rename this to avoid conflict with the like-named +-- function from Shared? Perhaps "addWarning"? warn :: PandocMonad m => String -> m () warn msg = modify $ \st -> st{stWarnings = msg : stWarnings st} @@ -183,6 +187,12 @@ runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma withMediaBag :: PandocMonad m => m a -> m (a, MediaBag) withMediaBag ma = ((,)) <$> ma <*> getMediaBag +withWarningsToStderr :: PandocIO a -> PandocIO a +withWarningsToStderr f = do + x <- f + getWarnings >>= mapM_ IO.warn + return x + runIOorExplode :: PandocIO a -> IO a runIOorExplode ma = handleError <$> runIO ma |