diff options
author | John MacFarlane <jgm@berkeley.edu> | 2010-12-10 23:21:24 -0800 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2010-12-10 23:21:24 -0800 |
commit | 2dfb45950ee0142f5454f5bab040e904dfaef21e (patch) | |
tree | adc8af9139b17430f3dc76544d040e5a4e31172b | |
parent | 9602f73f2a943c21a5d1593e99cdbcbde08f6dcb (diff) | |
download | pandoc-2dfb45950ee0142f5454f5bab040e904dfaef21e.tar.gz |
LaTeX reader: Improved parsing of preamble.
Previously you'd get unexpected behavior on a document that
contained '\begin{document}' in, say, a verbatim block.
-rw-r--r-- | src/Text/Pandoc/Readers/LaTeX.hs | 17 |
1 files changed, 6 insertions, 11 deletions
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") |