From 7db2cf5d2f637fc73377e32af776002e3670ef50 Mon Sep 17 00:00:00 2001 From: John MacFarlane <jgm@berkeley.edu> Date: Sat, 21 Nov 2020 12:24:37 -0800 Subject: [PATCH] LaTeX reader: more robust parsing of bracketed options. Improves on 9a40976. Closes #6873. --- src/Text/Pandoc/Readers/LaTeX.hs | 11 ++++++++--- test/command/6873.md | 7 +++++++ 2 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 test/command/6873.md diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 2ec191154..9b6cc0e3f 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -559,9 +559,14 @@ tok = try $ spaces >> grouped inline <|> inlineCommand' <|> singleChar' return $ str t opt :: PandocMonad m => LP m Inlines -opt = bracketed inline - <|> - (str . T.dropWhile (=='[') . T.dropWhileEnd (==']') <$> rawopt) +opt = do + toks <- try (sp *> bracketedToks <* sp) + -- now parse the toks as inlines + st <- getState + parsed <- runParserT (mconcat <$> many inline) st "bracketed option" toks + case parsed of + Right result -> return result + Left e -> throwError $ PandocParsecError (untokenize toks) e paropt :: PandocMonad m => LP m Inlines paropt = parenWrapped inline diff --git a/test/command/6873.md b/test/command/6873.md new file mode 100644 index 000000000..d747a47ff --- /dev/null +++ b/test/command/6873.md @@ -0,0 +1,7 @@ +``` +% pandoc -f latex -t native --citeproc +\cite[„Etwas […{]} auslassen“]{key} +^D +[WARNING] Citeproc: citation key not found +[Para [Cite [Citation {citationId = "key", citationPrefix = [], citationSuffix = [Str "\8222Etwas",Space,Str "[\8230",Span ("",[],[]) [Str "]"],Space,Str "auslassen\8220"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [Str "(",Strong [Str "key?"],Str "\8222Etwas",Space,Str "[\8230",Span ("",[],[]) [Str "]"],Space,Str "auslassen\8220)"]]] +```