aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2010-12-10 23:21:24 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2010-12-10 23:21:24 -0800
commit2dfb45950ee0142f5454f5bab040e904dfaef21e (patch)
treeadc8af9139b17430f3dc76544d040e5a4e31172b
parent9602f73f2a943c21a5d1593e99cdbcbde08f6dcb (diff)
downloadpandoc-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.hs17
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")