@@ -198,6 +198,7 @@ where
198198
199199import Prelude
200200import Control.Monad.Identity
201+import Control.Monad.Loops (unfoldM)
201202import Control.Monad.Reader
202203import Data.Char (chr, isAlphaNum, isAscii, isAsciiUpper,
203204 isPunctuation, isSpace, ord, toLower, toUpper)
@@ -221,6 +222,7 @@ import Text.Pandoc.Shared
221222import qualified Text.Pandoc.UTF8 as UTF8 (putStrLn)
222223import Text.Pandoc.XML (fromEntities)
223224import Text.Parsec hiding (token)
225+import qualified Text.Parsec (uncons)
224226import Text.Parsec.Pos (initialPos, newPos, updatePosString)
225227
226228import Control.Monad.Except
@@ -1044,13 +1046,18 @@ gridTableFooter = blanklines
10441046---
10451047
10461048-- | Removes the ParsecT layer from the monad transformer stack
1047−readWithM :: Monad m
1048− => ParserT [Char] st m a -- ^ parser
1049+readWithM :: (Monad m, Stream s m Char)
1050+ => ParserT s st m a -- ^ parser
10491051 -> st -- ^ initial state
1050− -> String -- ^ input
1052+ -> s -- ^ input
10511053 -> m (Either PandocError a)
1052−readWithM parser state input =
1053− mapLeft (PandocParsecError input) `liftM` runParserT parser state "source" input
1054+readWithM parser state input = do
1055+ res <- runParserT parser state "source" input
1056+ case res of
1057+ Right x -> return $ Right x
1058+ Left e -> do
1059+ inp <- map fst <$> unfoldM (Text.Parsec.uncons input)
1060+ return $ Left $ PandocParsecError inp e
10541061
10551062
10561063-- | Parse a string with a given parser and state