git.iko.soy/typeable/pandoc
on master help sign in
Fix for bug in parsing `\include` in markdown.

Starting in 2.2.2, everything after an `\input` (or `\include`) in a markdown file would be parsed as raw LaTeX. This commit fixes the issue and adds a regression test. Closes #4781.

commit34b229dd5a8493bad62498e5485f2775e2289ce8 authorJohn MacFarlane <jgm@berkeley.edu> dateThu 19 Jul 2018, 13:58 (8 years ago) parentac1a46b
2 files changed+32−1
src/Text/Pandoc/Readers/LaTeX.hs+10−1 test/command/4781.md+22
src/Text/Pandoc/Readers/LaTeX.hs+10−1
@@ -286,6 +286,12 @@ rawLaTeXBlock :: (PandocMonad m, HasMacros s, HasReaderOptions s)
286286rawLaTeXBlock = do
287287 lookAhead (try (char '\\' >> letter))
288288 snd <$> (rawLaTeXParser False macroDef blocks
289+ <|> (rawLaTeXParser True
290+ (do choice (map controlSeq
291+ ["include", "input", "subfile", "usepackage"])
292+ skipMany opt
293+ braced
294+ return mempty) blocks)
289295 <|> rawLaTeXParser True
290296 (environment <|> blockCommand)
291297 (mconcat <$> (many (block <|> beginOrEndCommand))))
@@ -308,7 +314,10 @@ rawLaTeXInline :: (PandocMonad m, HasMacros s, HasReaderOptions s)
308314 => ParserT String s m String
309315rawLaTeXInline = do
310316 lookAhead (try (char '\\' >> letter))
311− snd <$> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines
317+ snd <$> ( rawLaTeXParser True
318+ (mempty <$ (controlSeq "input" >> skipMany opt >> braced))
319+ inlines
320+ <|> rawLaTeXParser True (inlineEnvironment <|> inlineCommand') inlines)
312321
313322inlineCommand :: PandocMonad m => ParserT String ParserState m Inlines
314323inlineCommand = do
test/command/4781.mdnew file+22
@@ -0,0 +1,22 @@
1+```
2+% pandoc -t native
3+Markdown parsed *here*
4+
5+\include{command/bar}
6+
7+*But not here*
8+^D
9+[Para [Str "Markdown",Space,Str "parsed",Space,Emph [Str "here"]]
10+,RawBlock (Format "latex") "\\include{command/bar}"
11+,Para [Emph [Str "But",Space,Str "not",Space,Str "here"]]]
12+```
13+
14+```
15+% pandoc -t native
16+*here* \input{command/bar}
17+
18+*But not here*
19+^D
20+[Para [Emph [Str "here"],Space,RawInline (Format "tex") "\\input{command/bar}"]
21+,Para [Emph [Str "But",Space,Str "not",Space,Str "here"]]]
22+```