@@ -39,7 +39,8 @@ module Text.Pandoc.ParserCombinators (
40 stringAnyCase,
40 stringAnyCase,
41 parseFromStr,
41 parseFromStr,
42− lineClump
42+ lineClump,
44import Text.ParserCombinators.Parsec
45import Text.ParserCombinators.Parsec
45import Data.Char ( toUpper, toLower )
46import Data.Char ( toUpper, toLower )
@@ -122,3 +123,18 @@ lineClump = do
122 blanks <- blanklines <|> (do{eof; return "\n"})
123 blanks <- blanklines <|> (do{eof; return "\n"})
123 return ((unlines lines) ++ blanks)
124 return ((unlines lines) ++ blanks)
126+-- | Parse a string of characters between an open character
127+-- and a close character, including text between balanced
128+-- pairs of open and close. For example,
129+-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
130+-- and return "hello (there)".
131+charsInBalanced :: Char -> Char -> GenParser Char st String
132+charsInBalanced open close = try $ do
134+ raw <- manyTill ( (do res <- charsInBalanced open close
135+ return $ [open] ++ res ++ [close])
136+ <|> (do notFollowedBy' (blankline >> blanklines)