git.iko.soy/typeable/pandoc
on master help sign in
LaTeX reader: allow verbatim blocks ending with blank lines.

Closes #4624.

commit190ee279c9c10c6e87248428dcdbd73ab9036373 authorJohn MacFarlane <jgm@berkeley.edu> dateSat 29 Sep 2018, 10:57 (8 years ago) parentc6d56f0
2 files changed+44−1
src/Text/Pandoc/Readers/LaTeX.hs+14−1 test/command/4624.md+30
src/Text/Pandoc/Readers/LaTeX.hs+14−1
@@ -2145,7 +2145,20 @@ verbEnv name = withVerbatimMode $ do
21452145 skipopts
21462146 optional blankline
21472147 res <- manyTill anyTok (end_ name)
2148− return $ stripTrailingNewlines $ toksToString res
2148+ return $ T.unpack
2149+ $ stripTrailingNewline
2150+ $ untokenize
2151+ $ res
2152+
2153+-- Strip single final newline and any spaces following it.
2154+-- Input is unchanged if it doesn't end with newline +
2155+-- optional spaces.
2156+stripTrailingNewline :: Text -> Text
2157+stripTrailingNewline t =
2158+ let (b, e) = T.breakOnEnd "\n" t
2159+ in if T.all (== ' ') e
2160+ then T.dropEnd 1 b
2161+ else t
21492162
21502163fancyverbEnv :: PandocMonad m => Text -> LP m Blocks
21512164fancyverbEnv name = do
test/command/4624.mdnew file+30
@@ -0,0 +1,30 @@
1+```
2+% pandoc -f latex -t native
3+\begin{Verbatim}[key1=value1]
4+code1
5+
6+\end{Verbatim}
7+
8+
9+\begin{lstlisting}[key2=value2]
10+code2
11+
12+\end{lstlisting}
13+
14+\begin{verbatim}
15+code3
16+\end{verbatim}
17+
18+\begin{verbatim}
19+code4
20+ \end{verbatim}
21+
22+\begin{verbatim}
23+code5\end{verbatim}
24+^D
25+[CodeBlock ("",[],[("key1","value1")]) "code1\n"
26+,CodeBlock ("",[],[("key2","value2")]) "code2\n "
27+,CodeBlock ("",[],[]) "code3"
28+,CodeBlock ("",[],[]) "code4"
29+,CodeBlock ("",[],[]) "code5"]
30+```