Fix raw LaTeX injection issue (LaTeX writer).
Using a code block containing `\end{verbatim}`, one could inject raw TeX into a LaTeX document even when `raw_tex` is disabled. Thanks to Augustin Laville for noticing the bug. Closes #7497.
This commit is contained in:
parent
e8d7d157fd
commit
418155aa95
2 changed files with 47 additions and 5 deletions
|
@ -429,6 +429,7 @@ blockToLaTeX (BlockQuote lst) = do
|
||||||
blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
|
blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
|
||||||
opts <- gets stOptions
|
opts <- gets stOptions
|
||||||
lab <- labelFor identifier
|
lab <- labelFor identifier
|
||||||
|
inNote <- stInNote <$> get
|
||||||
linkAnchor' <- hypertarget True identifier lab
|
linkAnchor' <- hypertarget True identifier lab
|
||||||
let linkAnchor = if isEmpty linkAnchor'
|
let linkAnchor = if isEmpty linkAnchor'
|
||||||
then empty
|
then empty
|
||||||
|
@ -438,8 +439,7 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
|
||||||
return $ flush (linkAnchor $$ "\\begin{code}" $$ literal str $$
|
return $ flush (linkAnchor $$ "\\begin{code}" $$ literal str $$
|
||||||
"\\end{code}") $$ cr
|
"\\end{code}") $$ cr
|
||||||
let rawCodeBlock = do
|
let rawCodeBlock = do
|
||||||
st <- get
|
env <- if inNote
|
||||||
env <- if stInNote st
|
|
||||||
then modify (\s -> s{ stVerbInNote = True }) >>
|
then modify (\s -> s{ stVerbInNote = True }) >>
|
||||||
return "Verbatim"
|
return "Verbatim"
|
||||||
else return "verbatim"
|
else return "verbatim"
|
||||||
|
@ -475,14 +475,13 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
|
||||||
"\\end{lstlisting}") $$ cr
|
"\\end{lstlisting}") $$ cr
|
||||||
let highlightedCodeBlock =
|
let highlightedCodeBlock =
|
||||||
case highlight (writerSyntaxMap opts)
|
case highlight (writerSyntaxMap opts)
|
||||||
formatLaTeXBlock ("",classes,keyvalAttr) str of
|
formatLaTeXBlock ("",classes ++ ["default"],keyvalAttr) str of
|
||||||
Left msg -> do
|
Left msg -> do
|
||||||
unless (T.null msg) $
|
unless (T.null msg) $
|
||||||
report $ CouldNotHighlight msg
|
report $ CouldNotHighlight msg
|
||||||
rawCodeBlock
|
rawCodeBlock
|
||||||
Right h -> do
|
Right h -> do
|
||||||
st <- get
|
when inNote $ modify (\s -> s{ stVerbInNote = True })
|
||||||
when (stInNote st) $ modify (\s -> s{ stVerbInNote = True })
|
|
||||||
modify (\s -> s{ stHighlighting = True })
|
modify (\s -> s{ stHighlighting = True })
|
||||||
return (flush $ linkAnchor $$ text (T.unpack h))
|
return (flush $ linkAnchor $$ text (T.unpack h))
|
||||||
case () of
|
case () of
|
||||||
|
@ -491,6 +490,12 @@ blockToLaTeX (CodeBlock (identifier,classes,keyvalAttr) str) = do
|
||||||
| writerListings opts -> listingsCodeBlock
|
| writerListings opts -> listingsCodeBlock
|
||||||
| not (null classes) && isJust (writerHighlightStyle opts)
|
| not (null classes) && isJust (writerHighlightStyle opts)
|
||||||
-> highlightedCodeBlock
|
-> highlightedCodeBlock
|
||||||
|
-- we don't want to use \begin{verbatim} if our code
|
||||||
|
-- contains \end{verbatim}:
|
||||||
|
| inNote
|
||||||
|
, "\\end{Verbatim}" `T.isInfixOf` str -> highlightedCodeBlock
|
||||||
|
| not inNote
|
||||||
|
, "\\end{verbatim}" `T.isInfixOf` str -> highlightedCodeBlock
|
||||||
| otherwise -> rawCodeBlock
|
| otherwise -> rawCodeBlock
|
||||||
blockToLaTeX b@(RawBlock f x) = do
|
blockToLaTeX b@(RawBlock f x) = do
|
||||||
beamer <- gets stBeamer
|
beamer <- gets stBeamer
|
||||||
|
|
37
test/command/7497.md
Normal file
37
test/command/7497.md
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
````
|
||||||
|
% pandoc -f markdown-raw_tex -t latex
|
||||||
|
```
|
||||||
|
\end{verbatim}
|
||||||
|
\LaTeX
|
||||||
|
\begin{verbatim}
|
||||||
|
```
|
||||||
|
^D
|
||||||
|
\begin{Shaded}
|
||||||
|
\begin{Highlighting}[]
|
||||||
|
\NormalTok{\textbackslash{}end\{verbatim\}}
|
||||||
|
\NormalTok{\textbackslash{}LaTeX}
|
||||||
|
\NormalTok{\textbackslash{}begin\{verbatim\}}
|
||||||
|
\end{Highlighting}
|
||||||
|
\end{Shaded}
|
||||||
|
````
|
||||||
|
|
||||||
|
````
|
||||||
|
% pandoc -f markdown-raw_tex -t latex
|
||||||
|
hi[^1]
|
||||||
|
|
||||||
|
[^1]:
|
||||||
|
```
|
||||||
|
\end{Verbatim}
|
||||||
|
\LaTeX
|
||||||
|
\begin{Verbatim}
|
||||||
|
```
|
||||||
|
^D
|
||||||
|
hi\footnote{\begin{Shaded}
|
||||||
|
\begin{Highlighting}[]
|
||||||
|
\NormalTok{\textbackslash{}end\{Verbatim\}}
|
||||||
|
\NormalTok{\textbackslash{}LaTeX}
|
||||||
|
\NormalTok{\textbackslash{}begin\{Verbatim\}}
|
||||||
|
\end{Highlighting}
|
||||||
|
\end{Shaded}
|
||||||
|
}
|
||||||
|
````
|
Loading…
Add table
Reference in a new issue