git.iko.soy/typeable/pandoc
on master help sign in
Class: Add stateful IO warnings, and function to get warndings.
cc7191bJesse Rosenthal
src/Text/Pandoc/Class.hs+9−3
@@ -97,6 +97,7 @@ class (Functor m, Applicative m, Monad m, MonadError PandocExecutionError m) =>
97 -> String
97 -> String
98 -> m (Either E.SomeException (B.ByteString, Maybe MimeType))
98 -> m (Either E.SomeException (B.ByteString, Maybe MimeType))
99 warn :: String -> m ()
99 warn :: String -> m ()
100+ getWarnings :: m [String]
100 fail :: String -> m b
101 fail :: String -> m b
101 glob :: String -> m [FilePath]
102 glob :: String -> m [FilePath]
102
103
@@ -113,11 +114,11 @@ data PandocExecutionError = PandocFileReadError FilePath
113 deriving (Show, Typeable)
114 deriving (Show, Typeable)
114
115
115-- Nothing in this for now, but let's put it there anyway.
116-- Nothing in this for now, but let's put it there anyway.
116−data PandocStateIO = PandocStateIO
117+data PandocStateIO = PandocStateIO { ioStWarnings :: [String] }
117 deriving Show
118 deriving Show
118
119
119instance Default PandocStateIO where
120instance Default PandocStateIO where
120− def = PandocStateIO
121+ def = PandocStateIO { ioStWarnings = [] }
121
122
122runIO :: PandocIO a -> IO (Either PandocExecutionError a)
123runIO :: PandocIO a -> IO (Either PandocExecutionError a)
123runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
124runIO ma = flip evalStateT def $ runExceptT $ unPandocIO ma
@@ -156,7 +157,10 @@ instance PandocMonad PandocIO where
156 fail = M.fail
157 fail = M.fail
157 fetchItem ms s = liftIO $ IO.fetchItem ms s
158 fetchItem ms s = liftIO $ IO.fetchItem ms s
158 fetchItem' mb ms s = liftIO $ IO.fetchItem' mb ms s
159 fetchItem' mb ms s = liftIO $ IO.fetchItem' mb ms s
160+ warn msg = do
161+ modify $ \st -> st{ioStWarnings = msg : ioStWarnings st}
159− warn = liftIO . IO.warn
162+ liftIO $ IO.warn msg
163+ getWarnings = gets ioStWarnings
160 glob = liftIO . IO.glob
164 glob = liftIO . IO.glob
161
165
162data TestState = TestState { stStdGen :: StdGen
166data TestState = TestState { stStdGen :: StdGen
@@ -266,6 +270,8 @@ instance PandocMonad PandocPure where
266
270
267 warn s = modify $ \st -> st { stWarnings = s : stWarnings st }
271 warn s = modify $ \st -> st { stWarnings = s : stWarnings st }
268
272
273+ getWarnings = gets stWarnings
274+
269 glob s = do
275 glob s = do
270 fontFiles <- asks envFontFiles
276 fontFiles <- asks envFontFiles
271 return (filter (match (compile s)) fontFiles)
277 return (filter (match (compile s)) fontFiles)