git.iko.soy/typeable/pandoc
on master help sign in
New withWarningsToStderr exported from Text.Pandoc.Class.

And use this in pandoc.hs so that messages actually get printed.

commit5ab8909661242d992726411d6adc6490eacaafe3 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 3 Dec 2016, 16:57 (10 years ago) parent29b3975
2 files changed+23−6
pandoc.hs+12−5 src/Text/Pandoc/Class.hs+11−1
pandoc.hs+12−5
@@ -77,7 +77,7 @@ import System.Posix.Terminal (queryTerminal)
7777import System.Posix.IO (stdOutput)
7878#endif
7979import Control.Monad.Trans
80−import Text.Pandoc.Class (withMediaBag, PandocIO)
80+import Text.Pandoc.Class (withMediaBag, PandocIO, withWarningsToStderr)
8181
8282type Transform = Pandoc -> Pandoc
8383
@@ -1414,10 +1414,14 @@ convertWithOpts opts args = do
14141414 srcs <- convertTabs . intercalate "\n" <$> readSources sources'
14151415 doc <- handleIncludes' srcs
14161416 case doc of
1417− Right doc' -> runIOorExplode $ withMediaBag $ r readerOpts doc'
1417+ Right doc' -> runIOorExplode $ withMediaBag
1418+ $ withWarningsToStderr
1419+ $ r readerOpts doc'
14181420 Left e -> error $ show e
14191421 ByteStringReader r -> readFiles sources' >>=
1420− (\bs -> runIOorExplode $ withMediaBag $ r readerOpts bs)
1422+ (\bs -> runIOorExplode $ withMediaBag
1423+ $ withWarningsToStderr
1424+ $ r readerOpts bs)
14211425
14221426 -- We parse first if (1) fileScope is set, (2), it's a binary
14231427 -- reader, or (3) we're reading JSON. This is easier to do of an AND
@@ -1489,7 +1493,9 @@ convertWithOpts opts args = do
14891493
14901494 case writer of
14911495 -- StringWriter f -> f writerOptions doc' >>= writerFn outputFile
1492− ByteStringWriter f -> (runIOorExplode $ f writerOptions doc') >>= writeFnBinary outputFile
1496+ ByteStringWriter f -> (runIOorExplode $ withWarningsToStderr
1497+ $ f writerOptions doc')
1498+ >>= writeFnBinary outputFile
14931499 StringWriter f
14941500 | pdfOutput -> do
14951501 -- make sure writer is latex or beamer or context or html5
@@ -1523,5 +1529,6 @@ convertWithOpts opts args = do
15231529 handleEntities = if htmlFormat && ascii
15241530 then toEntities
15251531 else id
1526− output <- runIOorExplode $ f writerOptions doc'
1532+ output <- runIOorExplode $ withWarningsToStderr
1533+ $ f writerOptions doc'
15271534 selfcontain (output ++ ['\n' | not standalone']) >>= writerFn outputFile . handleEntities
src/Text/Pandoc/Class.hs+11−1
@@ -51,6 +51,7 @@ module Text.Pandoc.Class ( PandocMonad(..)
5151 , runIOorExplode
5252 , runPure
5353 , withMediaBag
54+ , withWarningsToStderr
5455 ) where
5556
5657import Prelude hiding (readFile, fail)
@@ -64,7 +65,8 @@ import qualified Text.Pandoc.Shared as IO ( fetchItem
6465 , fetchItem'
6566 , getDefaultReferenceDocx
6667 , getDefaultReferenceODT
67− , readDataFile)
68+ , readDataFile
69+ , warn)
6870import Text.Pandoc.Compat.Time (UTCTime)
6971import Text.Pandoc.Parsing (ParserT, ParserState, SourcePos)
7072import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
@@ -119,6 +121,8 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m, MonadState C
119121
120122-- Functions defined for all PandocMonad instances
121123
124+-- TODO should we rename this to avoid conflict with the like-named
125+-- function from Shared? Perhaps "addWarning"?
122126warn :: PandocMonad m => String -> m ()
123127warn msg = modify $ \st -> st{stWarnings = msg : stWarnings st}
124128
@@ -183,6 +187,12 @@ runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
183187withMediaBag :: PandocMonad m => m a -> m (a, MediaBag)
184188withMediaBag ma = ((,)) <$> ma <*> getMediaBag
185189
190+withWarningsToStderr :: PandocIO a -> PandocIO a
191+withWarningsToStderr f = do
192+ x <- f
193+ getWarnings >>= mapM_ IO.warn
194+ return x
195+
186196runIOorExplode :: PandocIO a -> IO a
187197runIOorExplode ma = handleError <$> runIO ma
188198