git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Fix parsing of optional arguments that contain braced text.

Closes #5740.

commit4778d034734e4848688c1fb5fa196b8bda8f08f2 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 9 Sep 2019, 21:33 (7 years ago) parent4dad7c5
2 files changed+12−4
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+3−4 test/command/5740.md+9
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+3−4
@@ -93,8 +93,6 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
9393import Text.Pandoc.Shared
9494import Text.Parsec.Pos
9595
96−-- import Debug.Trace (traceShowId)
97−
9896newtype DottedNum = DottedNum [Int]
9997 deriving (Show)
10098
@@ -447,7 +445,7 @@ doMacros' n inp = do
447445 args <- case optarg of
448446 Nothing -> getargs M.empty argspecs
449447 Just o -> do
450− x <- option o bracketedToks
448+ x <- option o $ bracketedToks
451449 getargs (M.singleton 1 x) $ drop 1 argspecs
452450 rest <- getInput
453451 return (args, rest)
@@ -644,7 +642,8 @@ bracketed parser = try $ do
644642bracketedToks :: PandocMonad m => LP m [Tok]
645643bracketedToks = do
646644 symbol '['
647− mconcat <$> manyTill (braced <|> (:[]) <$> anyTok) (symbol ']')
645+ concat <$> manyTill ((snd <$> withRaw (try braced)) <|> count 1 anyTok)
646+ (symbol ']')
648647
649648parenWrapped :: PandocMonad m => Monoid a => LP m a -> LP m a
650649parenWrapped parser = try $ do
test/command/5740.mdnew file+9
@@ -0,0 +1,9 @@
1+```
2+% pandoc -t latex
3+\newcommand\parenthesize[1][x]{(#1)}
4+$\parenthesize$, $\parenthesize[y]$, $\parenthesize[\textsc{head}]$
5+^D
6+\newcommand\parenthesize[1][x]{(#1)}
7+
8+\((x)\), \((y)\), \((\textsc{head})\)
9+```