From 2dfb45950ee0142f5454f5bab040e904dfaef21e Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 10 Dec 2010 23:21:24 -0800 Subject: LaTeX reader: Improved parsing of preamble. Previously you'd get unexpected behavior on a document that contained '\begin{document}' in, say, a verbatim block. --- src/Text/Pandoc/Readers/LaTeX.hs | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/Text/Pandoc') diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs index 406809dfc..0bc13d2dd 100644 --- a/src/Text/Pandoc/Readers/LaTeX.hs +++ b/src/Text/Pandoc/Readers/LaTeX.hs @@ -119,20 +119,15 @@ anyEnvironment = try $ do -- | Process LaTeX preamble, extracting metadata. processLaTeXPreamble :: GenParser Char ParserState () -processLaTeXPreamble = try $ manyTill - (choice [bibliographic, comment, unknownCommand, nullBlock]) - (try (string "\\begin{document}")) >> - spaces +processLaTeXPreamble = + skipMany $ notFollowedBy' anyEnvironment >> block -- | Parse LaTeX and return 'Pandoc'. parseLaTeX :: GenParser Char ParserState Pandoc parseLaTeX = do - optional processLaTeXPreamble -- preamble might not be present (fragment) - spaces - blocks <- parseBlocks spaces - optional $ try (string "\\end{document}" >> many anyChar) - -- might not be present (fragment) + blocks <- try (processLaTeXPreamble >> spaces >> environment "document") + <|> many block spaces eof state <- getState @@ -420,8 +415,8 @@ ignore = try $ do unknownCommand :: GenParser Char ParserState Block unknownCommand = try $ do - notFollowedBy' $ choice $ map end ["itemize", "enumerate", "description", - "document"] + spaces + notFollowedBy' $ oneOfStrings ["\\begin","\\end","\\item"] state <- getState when (stateParserContext state == ListItemState) $ notFollowedBy' (string "\\item") -- cgit v1.2.3