From a088d67f0d7212c96f5b59c568f0fc61a1106be4 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Thu, 9 Mar 2017 21:03:54 +0100 Subject: LaTeX reader: Treat `{{xxx}}` the same as `{xxx}`. Closes #2115. --- src/Text/Pandoc/Readers/LaTeX.hs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 60113173d..48266f894 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -147,17 +147,22 @@ egroup = () <$ char '}' <|> () <$ controlSeq "endgroup" grouped :: PandocMonad m => Monoid a => LP m a -> LP m a -grouped parser = try $ bgroup *> (mconcat <$> manyTill parser egroup) +grouped parser = try $ do + bgroup + -- first we check for an inner 'grouped', because + -- {{a,b}} should be parsed the same as {a,b} + try (grouped parser <* egroup) + <|> (mconcat <$> manyTill parser egroup) braced :: PandocMonad m => LP m String -braced = bgroup *> (concat <$> manyTill - ( many1 (satisfy (\c -> c /= '\\' && c /= '}' && c /= '{')) - <|> try (string "\\}") - <|> try (string "\\{") - <|> try (string "\\\\") - <|> ((\x -> "{" ++ x ++ "}") <$> braced) - <|> count 1 anyChar - ) egroup) +braced = grouped chunk + where chunk = + many1 (satisfy (\c -> c /= '\\' && c /= '}' && c /= '{')) + <|> try (string "\\}") + <|> try (string "\\{") + <|> try (string "\\\\") + <|> ((\x -> "{" ++ x ++ "}") <$> braced) + <|> count 1 anyChar bracketed :: PandocMonad m => Monoid a => LP m a -> LP m a bracketed parser = try $ char '[' *> (mconcat <$> manyTill parser (char ']')) -- cgit v1.2.3