@@ -680,28 +680,25 @@ grouped parser = try $ do
680680 -- {{a,b}} should be parsed the same as {a,b}
681681 try (grouped parser <* egroup) <|> (mconcat <$> manyTill parser egroup)
682682
683−braced' :: PandocMonad m => LP m Tok -> Int -> LP m [Tok]
684−braced' getTok n =
685− handleEgroup <|> handleBgroup <|> handleOther
686− where handleEgroup = do
687− t <- symbol '}'
688− if n == 1
689− then return []
690− else (t:) <$> braced' getTok (n - 1)
691− handleBgroup = do
692− t <- symbol '{'
693− (t:) <$> braced' getTok (n + 1)
694− handleOther = do
695− t <- getTok
696− (t:) <$> braced' getTok n
683+braced' :: PandocMonad m => LP m Tok -> LP m [Tok]
684+braced' getTok = symbol '{' *> go (1 :: Int)
685+ where
686+ go n = do
687+ t <- getTok
688+ case t of
689+ Tok _ Symbol "}"
690+ | n > 1 -> (t:) <$> go (n - 1)
691+ | otherwise -> return []
692+ Tok _ Symbol "{" -> (t:) <$> go (n + 1)
693+ _ -> (t:) <$> go n
697694
698695braced :: PandocMonad m => LP m [Tok]
699−braced = symbol '{' *> braced' anyTok 1
696+braced = braced' anyTok
700697
701698-- URLs require special handling, because they can contain %
702699-- characters. So we retonenize comments as we go...
703700bracedUrl :: PandocMonad m => LP m [Tok]
704−bracedUrl = bgroup *> braced' (retokenizeComment >> anyTok) 1
701+bracedUrl = braced' (retokenizeComment >> anyTok)
705702
706703-- For handling URLs, which allow literal % characters...
707704retokenizeComment :: PandocMonad m => LP m ()