git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: more robust parsing of unknown environments.

We no longer fail on things like `^` inside options for tikz. Closes #3026.

commit1b6c9733eeda3f4d3486b90f4712d9e6d3a4624b authorJohn MacFarlane <jgm@berkeley.edu> dateWed 20 Jul 2016, 11:18 (10 years ago) parent5611de1
1 file changed+9−2
src/Text/Pandoc/Readers/LaTeX.hs+9−2
src/Text/Pandoc/Readers/LaTeX.hs+9−2
@@ -859,8 +859,14 @@ tok = try $ grouped inline <|> inlineCommand <|> str <$> count 1 inlineChar
859859opt :: LP Inlines
860860opt = bracketed inline
861861
862+rawopt :: LP String
863+rawopt = do
864+ contents <- bracketed (many1 (noneOf "]") <|> try (string "\\]"))
865+ optional sp
866+ return $ "[" ++ contents ++ "]"
867+
862868skipopts :: LP ()
863−skipopts = skipMany (opt *> optional sp)
869+skipopts = skipMany rawopt
864870
865871inlineText :: LP Inlines
866872inlineText = str <$> many1 inlineChar
@@ -883,8 +889,9 @@ inlineEnvironment = try $ do
883889
884890rawEnv :: String -> LP Blocks
885891rawEnv name = do
886− let addBegin x = "\\begin{" ++ name ++ "}" ++ x
887892 parseRaw <- getOption readerParseRaw
893+ rawOptions <- mconcat <$> many rawopt
894+ let addBegin x = "\\begin{" ++ name ++ "}" ++ rawOptions ++ x
888895 if parseRaw
889896 then (rawBlock "latex" . addBegin) <$>
890897 (withRaw (env name blocks) >>= applyMacros' . snd)