diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/ParserCombinators.hs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/src/Text/Pandoc/ParserCombinators.hs b/src/Text/Pandoc/ParserCombinators.hs index 7a129b6be..2e4c1413c 100644 --- a/src/Text/Pandoc/ParserCombinators.hs +++ b/src/Text/Pandoc/ParserCombinators.hs @@ -39,7 +39,8 @@ module Text.Pandoc.ParserCombinators ( enclosed, stringAnyCase, parseFromStr, - lineClump + lineClump, + charsInBalanced ) where import Text.ParserCombinators.Parsec import Data.Char ( toUpper, toLower ) @@ -122,3 +123,18 @@ lineClump = do blanks <- blanklines <|> (do{eof; return "\n"}) return ((unlines lines) ++ blanks) +-- | Parse a string of characters between an open character +-- and a close character, including text between balanced +-- pairs of open and close. For example, +-- @charsInBalanced '(' ')'@ will parse "(hello (there))" +-- and return "hello (there)". +charsInBalanced :: Char -> Char -> GenParser Char st String +charsInBalanced open close = try $ do + char open + raw <- manyTill ( (do res <- charsInBalanced open close + return $ [open] ++ res ++ [close]) + <|> (do notFollowedBy' (blankline >> blanklines) + count 1 anyChar)) + (char close) + return $ concat raw + |