diff options
author | John MacFarlane <jgm@berkeley.edu> | 2021-12-07 23:52:29 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2021-12-07 23:52:29 -0800 |
commit | 45e51ecd65beb663973508799bd7cfd6a304930b (patch) | |
tree | 7bcfb828369f196d97d6fbd3620190dc588058c4 /src | |
parent | 51142c6803cab7486dbe962f274174d246e571aa (diff) | |
download | pandoc-45e51ecd65beb663973508799bd7cfd6a304930b.tar.gz |
Revert "Markdown reader: Improve inlinesInBalancedBrackets."
This reverts commit fa83246d7de8527bbf59dfac9636a42ede185194.
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Markdown.hs | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs index 0d4592599..d5a4c322f 100644 --- a/src/Text/Pandoc/Readers/Markdown.hs +++ b/src/Text/Pandoc/Readers/Markdown.hs @@ -188,18 +188,26 @@ litChar = escapedChar' -- including inlines between balanced pairs of square brackets. inlinesInBalancedBrackets :: PandocMonad m => MarkdownParser m (F Inlines) inlinesInBalancedBrackets = - mconcat <$> try (char '[' >> go (1 :: Int)) - where - go n = - (:) <$> (note <|> cite <|> bracketedSpan <|> link) <*> go n - <|> - (char '[' *> ((:) <$> pure (pure (B.str "[")) <*> go (n + 1))) - <|> - (char ']' *> (if n > 1 - then (:) <$> pure (pure (B.str "]")) <*> go (n - 1) - else pure [])) - <|> - (:) <$> inline <*> go n + try $ char '[' >> withRaw (go 1) >>= + parseFromString inlines . stripBracket . snd + where stripBracket t = case T.unsnoc t of + Just (t', ']') -> t' + _ -> t + go :: PandocMonad m => Int -> MarkdownParser m () + go 0 = return () + go openBrackets = + (() <$ (escapedChar <|> + code <|> + math <|> + rawHtmlInline <|> + rawLaTeXInline') >> go openBrackets) + <|> + (do char ']' + Control.Monad.when (openBrackets > 1) $ go (openBrackets - 1)) + <|> + (char '[' >> go (openBrackets + 1)) + <|> + (anyChar >> go openBrackets) -- -- document structure |