git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: allow spaces btw \\begin or \\end and {.
303ce8aJohn MacFarlane
src/Text/Pandoc/Readers/LaTeX.hs+27−10
@@ -86,14 +86,22 @@ command = do
86
86
87begin :: [Char] -> GenParser Char st [Char]
87begin :: [Char] -> GenParser Char st [Char]
88begin name = try $ do
88begin name = try $ do
89− string $ "\\begin{" ++ name ++ "}"
89+ string "\\begin"
90+ spaces
91+ char '{'
92+ string name
93+ char '}'
90 optional commandArgs
94 optional commandArgs
91 spaces
95 spaces
92 return name
96 return name
93
97
94end :: [Char] -> GenParser Char st [Char]
98end :: [Char] -> GenParser Char st [Char]
95end name = try $ do
99end name = try $ do
96− string $ "\\end{" ++ name ++ "}"
100+ string "\\end"
101+ spaces
102+ char '{'
103+ string name
104+ char '}'
97 return name
105 return name
98
106
99-- | Returns a list of block elements containing the contents of an
107-- | Returns a list of block elements containing the contents of an
@@ -103,7 +111,9 @@ environment name = try $ begin name >> spaces >> manyTill block (end name) >>~ s
103
111
104anyEnvironment :: GenParser Char ParserState Block
112anyEnvironment :: GenParser Char ParserState Block
105anyEnvironment = try $ do
113anyEnvironment = try $ do
106− string "\\begin{"
114+ string "\\begin"
115+ spaces
116+ char '{'
107 name <- many letter
117 name <- many letter
108 star <- option "" (string "*") -- some environments have starred variants
118 star <- option "" (string "*") -- some environments have starred variants
109 char '}'
119 char '}'
@@ -215,10 +225,10 @@ codeBlock = codeBlockWith "verbatim" <|> codeBlockWith "Verbatim" <|> codeBlockW
215
225
216codeBlockWith :: String -> GenParser Char st Block
226codeBlockWith :: String -> GenParser Char st Block
217codeBlockWith env = try $ do
227codeBlockWith env = try $ do
228+ string "\\begin"
218− string ("\\begin{" ++ env ++ "}") -- don't use begin function because it
229+ spaces -- don't use begin function because it
219− -- gobbles whitespace
230+ string $ "{" ++ env ++ "}" -- gobbles whitespace; we want to gobble
220− optional blanklines -- we want to gobble blank lines, but not
221− -- leading space
231+ optional blanklines -- blank lines, but not leading space
222 contents <- manyTill anyChar (try (string $ "\\end{" ++ env ++ "}"))
232 contents <- manyTill anyChar (try (string $ "\\end{" ++ env ++ "}"))
223 spaces
233 spaces
224 let classes = if env == "code" then ["haskell"] else []
234 let classes = if env == "code" then ["haskell"] else []
@@ -262,7 +272,10 @@ listItem = try $ do
262
272
263orderedList :: GenParser Char ParserState Block
273orderedList :: GenParser Char ParserState Block
264orderedList = try $ do
274orderedList = try $ do
265− string "\\begin{enumerate}"
275+ string "\\begin"
276+ spaces
277+ string "{enumerate}"
278+ spaces
266 (_, style, delim) <- option (1, DefaultStyle, DefaultDelim) $
279 (_, style, delim) <- option (1, DefaultStyle, DefaultDelim) $
267 try $ do failIfStrict
280 try $ do failIfStrict
268 char '['
281 char '['
@@ -383,7 +396,9 @@ rawLaTeXEnvironment = do
383-- the whole literal environment as raw TeX.
396-- the whole literal environment as raw TeX.
384rawLaTeXEnvironment' :: GenParser Char st String
397rawLaTeXEnvironment' :: GenParser Char st String
385rawLaTeXEnvironment' = try $ do
398rawLaTeXEnvironment' = try $ do
386− string "\\begin{"
399+ string "\\begin"
400+ spaces
401+ char '{'
387 name <- many1 letter
402 name <- many1 letter
388 star <- option "" (string "*") -- for starred variants
403 star <- option "" (string "*") -- for starred variants
389 let name' = name ++ star
404 let name' = name ++ star
@@ -448,7 +463,9 @@ commandsToIgnore = ["special","pdfannot","pdfstringdef", "index","bibliography"]
448skipChar :: GenParser Char ParserState Block
463skipChar :: GenParser Char ParserState Block
449skipChar = do
464skipChar = do
450 satisfy (/='\\') <|>
465 satisfy (/='\\') <|>
466+ (notFollowedBy' (try $
451− (notFollowedBy' (lookAhead $ string "\\begin{document}") >> anyChar)
467+ string "\\begin" >> spaces >> string "{document}") >>
468+ anyChar)
452 spaces
469 spaces
453 return Null
470 return Null
454
471
tests/latex-reader.latex+1−1
@@ -71,7 +71,7 @@ E-mail style:
71This is a block quote. It is pretty short.
71This is a block quote. It is pretty short.
72
72
73\end{quote}
73\end{quote}
74−\begin{quote}
74+\begin {quote}
75Code in a block quote:
75Code in a block quote:
76
76
77\begin{verbatim}
77\begin{verbatim}