@@ -293,28 +293,28 @@ lineClump = do
294-- | Parse a string of characters between an open character
294-- | Parse a string of characters between an open character
295-- and a close character, including text between balanced
295-- and a close character, including text between balanced
296−-- pairs of open and close. For example,
296+-- pairs of open and close, which must be different. For example,
297-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
297-- @charsInBalanced '(' ')'@ will parse "(hello (there))"
298-- and return "hello (there)". Stop if a blank line is
298-- and return "hello (there)". Stop if a blank line is
299-- encountered.
299-- encountered.
300charsInBalanced :: Char -> Char -> GenParser Char st String
300charsInBalanced :: Char -> Char -> GenParser Char st String
301charsInBalanced open close = try $ do
301charsInBalanced open close = try $ do
302 char open
302 char open
303+ raw <- many $ (many1 (noneOf [open, close, '\n']))
303− raw <- manyTill ( (do res <- charsInBalanced open close
304+ <|> (do res <- charsInBalanced open close
304− return $ [open] ++ res ++ [close])
305+ return $ [open] ++ res ++ [close])
305− <|> (do notFollowedBy (blankline >> blanklines >> return '\n')
306+ <|> try (string "\n" >>~ notFollowedBy' blanklines)
307− (char close)
307+ char close
308 return $ concat raw
308 return $ concat raw
310-- | Like @charsInBalanced@, but allow blank lines in the content.
310-- | Like @charsInBalanced@, but allow blank lines in the content.
311charsInBalanced' :: Char -> Char -> GenParser Char st String
311charsInBalanced' :: Char -> Char -> GenParser Char st String
312charsInBalanced' open close = try $ do
312charsInBalanced' open close = try $ do
313 char open
313 char open
314+ raw <- many $ (many1 (noneOf [open, close]))
314− raw <- manyTill ( (do res <- charsInBalanced open close
315+ <|> (do res <- charsInBalanced' open close
315 return $ [open] ++ res ++ [close])
316 return $ [open] ++ res ++ [close])
316− <|> count 1 anyChar)
317− (char close)
317+ char close
318 return $ concat raw
318 return $ concat raw
320-- | Parses a roman numeral (uppercase or lowercase), returns number.
320-- | Parses a roman numeral (uppercase or lowercase), returns number.