git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: Fix parsing of optional arguments that contain braced text.
4778d03John MacFarlane
src/Text/Pandoc/Readers/LaTeX/Parsing.hs+3−4
@@ -93,8 +93,6 @@ import Text.Pandoc.Readers.LaTeX.Types (ExpansionPoint (..), Macro (..),
93import Text.Pandoc.Shared
93import Text.Pandoc.Shared
94import Text.Parsec.Pos
94import Text.Parsec.Pos
95
95
96−-- import Debug.Trace (traceShowId)
97−
98newtype DottedNum = DottedNum [Int]
96newtype DottedNum = DottedNum [Int]
99 deriving (Show)
97 deriving (Show)
100
98
@@ -447,7 +445,7 @@ doMacros' n inp = do
447 args <- case optarg of
445 args <- case optarg of
448 Nothing -> getargs M.empty argspecs
446 Nothing -> getargs M.empty argspecs
449 Just o -> do
447 Just o -> do
450− x <- option o bracketedToks
448+ x <- option o $ bracketedToks
451 getargs (M.singleton 1 x) $ drop 1 argspecs
449 getargs (M.singleton 1 x) $ drop 1 argspecs
452 rest <- getInput
450 rest <- getInput
453 return (args, rest)
451 return (args, rest)
@@ -644,7 +642,8 @@ bracketed parser = try $ do
644bracketedToks :: PandocMonad m => LP m [Tok]
642bracketedToks :: PandocMonad m => LP m [Tok]
645bracketedToks = do
643bracketedToks = do
646 symbol '['
644 symbol '['
647− mconcat <$> manyTill (braced <|> (:[]) <$> anyTok) (symbol ']')
645+ concat <$> manyTill ((snd <$> withRaw (try braced)) <|> count 1 anyTok)
646+ (symbol ']')
648
647
649parenWrapped :: PandocMonad m => Monoid a => LP m a -> LP m a
648parenWrapped :: PandocMonad m => Monoid a => LP m a -> LP m a
650parenWrapped parser = try $ do
649parenWrapped 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+```