@@ -37,6 +37,7 @@ A utility library with parsers used in pandoc readers.
3737-}
3838module Text.Pandoc.Parsing ( anyLine,
3939 anyLineNewline,
40+ indentWith,
4041 many1Till,
4142 notFollowedBy',
4243 oneOfStrings,
@@ -260,6 +261,17 @@ anyLine = do
260261anyLineNewline :: Stream [Char] m Char => ParserT [Char] st m [Char]
261262anyLineNewline = (++ "\n") <$> anyLine
262263
264+-- | Parse indent by specified number of spaces (or equiv. tabs)
265+indentWith :: Stream [Char] m Char
266+ => HasReaderOptions st
267+ => Int -> ParserT [Char] st m [Char]
268+indentWith num = do
269+ tabStop <- getOption readerTabStop
270+ if (num < tabStop)
271+ then count num (char ' ')
272+ else choice [ try (count num (char ' '))
273+ , try (char '\t' >> indentWith (num - tabStop)) ]
274+
263275-- | Like @manyTill@, but reads at least one item.
264276many1Till :: Stream s m t
265277 => ParserT s st m a