diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-04-19 17:02:59 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-04-19 17:04:33 -0700 |
commit | e9d7504bea5add902f95806a2dbac0248899777d (patch) | |
tree | 0b976dfb175b7a8fd01b28c6e15a3eeaa367d00a /src | |
parent | 5b5813c30b458d3eee96e8e5be5c44451b2037b8 (diff) | |
download | pandoc-e9d7504bea5add902f95806a2dbac0248899777d.tar.gz |
Rewrote charsInBalancedBrackets.
This version should be a bit more efficient.
This doesn't help with #1735, however.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index b54b947b4..102c42ab2 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -165,19 +165,22 @@ litChar = escapedChar' -- | Parse a sequence of inline elements between square brackets, -- including inlines between balanced pairs of square brackets. inlinesInBalancedBrackets :: MarkdownParser (F Inlines) -inlinesInBalancedBrackets = charsInBalancedBrackets >>= - parseFromString (trimInlinesF . mconcat <$> many inline) - -charsInBalancedBrackets :: MarkdownParser [Char] -charsInBalancedBrackets = do +inlinesInBalancedBrackets = do char '[' - result <- manyTill ( many1 (noneOf "`[]\n") - <|> (snd <$> withRaw code) - <|> ((\xs -> '[' : xs ++ "]") <$> charsInBalancedBrackets) - <|> count 1 (satisfy (/='\n')) - <|> (newline >> notFollowedBy blankline >> return "\n") - ) (char ']') - return $ concat result + (_, raw) <- withRaw $ charsInBalancedBrackets 1 + guard $ not $ null raw + parseFromString (trimInlinesF . mconcat <$> many inline) (init raw) + +charsInBalancedBrackets :: Int -> MarkdownParser () +charsInBalancedBrackets 0 = return () +charsInBalancedBrackets openBrackets = + (char '[' >> charsInBalancedBrackets (openBrackets + 1)) + <|> (char ']' >> charsInBalancedBrackets (openBrackets - 1)) + <|> (( (() <$ code) + <|> (() <$ escapedChar') + <|> (newline >> notFollowedBy blankline) + <|> skipMany1 (noneOf "[]`\n\\") + ) >> charsInBalancedBrackets openBrackets) -- -- document structure |