summaryrefslogtreecommitdiff
path: root/src/Text/Pandoc/Parsing.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Text/Pandoc/Parsing.hs')
-rw-r--r--src/Text/Pandoc/Parsing.hs12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/Text/Pandoc/Parsing.hs b/src/Text/Pandoc/Parsing.hs
index ce2523d12..e430c7cb5 100644
--- a/src/Text/Pandoc/Parsing.hs
+++ b/src/Text/Pandoc/Parsing.hs
@@ -37,6 +37,7 @@ A utility library with parsers used in pandoc readers.
-}
module Text.Pandoc.Parsing ( anyLine,
anyLineNewline,
+ indentWith,
many1Till,
notFollowedBy',
oneOfStrings,
@@ -260,6 +261,17 @@ anyLine = do
anyLineNewline :: Stream [Char] m Char => ParserT [Char] st m [Char]
anyLineNewline = (++ "\n") <$> anyLine
+-- | Parse indent by specified number of spaces (or equiv. tabs)
+indentWith :: Stream [Char] m Char
+ => HasReaderOptions st
+ => Int -> ParserT [Char] st m [Char]
+indentWith num = do
+ tabStop <- getOption readerTabStop
+ if (num < tabStop)
+ then count num (char ' ')
+ else choice [ try (count num (char ' '))
+ , try (char '\t' >> indentWith (num - tabStop)) ]
+
-- | Like @manyTill@, but reads at least one item.
many1Till :: Stream s m t
=> ParserT s st m a