@@ -21,7 +21,7 @@
2121A utility library with parsers used in pandoc readers.
2222-}
2323
24−module Text.Pandoc.Parsing ( takeWhileP,
24+module Text.Pandoc.Parsing ( take1WhileP,
2525 takeP,
2626 countChar,
2727 textStr,
@@ -264,19 +264,21 @@ textStr :: Stream s m Char => Text -> ParsecT s u m Text
264264textStr t = string (T.unpack t) $> t
265265
266266-- | Parse characters while a predicate is true.
267−takeWhileP :: Monad m
267+take1WhileP :: Monad m
268268 => (Char -> Bool)
269269 -> ParserT Text st m Text
270−takeWhileP f = do
271− -- faster than 'many (satisfy f)'
270+take1WhileP f = do
271+ -- needed to persuade parsec that this won't match an empty string:
272+ c <- satisfy f
272273 inp <- getInput
273274 pos <- getPosition
274− let (xs, rest) = T.span f inp
275− -- needed to persuade parsec that this won't match an empty string:
276− anyChar
275+ let (t, rest) = T.span f inp
277276 setInput rest
278− setPosition $ updatePosString pos $ T.unpack xs
279− return xs
277+ setPosition $
278+ if f '\t' || f '\n'
279+ then updatePosString pos $ T.unpack t
280+ else incSourceColumn pos (T.length t)
281+ return $ T.singleton c <> t
280282
281283-- Parse n characters of input (or the rest of the input if
282284-- there aren't n characters).