Skip to content

Escape \end{verbatim} inside latex code blocks - #643

Open
zayeem06 wants to merge 1 commit into
commonmark:masterfrom
zayeem06:latex-verbatim-escape
Open

zayeem06 wants to merge 1 commit into
commonmark:masterfrom
zayeem06:latex-verbatim-escape

Conversation

@zayeem06

Copy link
Copy Markdown
Contributor

The latex renderer writes a code block's contents unescaped inside \begin{verbatim}, and LaTeX ends that environment at the first literal \end{verbatim}, so a code block containing that line closes the environment early and the rest of the block is compiled as TeX. For example, cmark -t latex on a code block whose lines are \end{verbatim} and \newread\r\openin\r=secret.txt\read\r to\x\message{\x} prints the contents of secret.txt when the output is compiled (checked with tectonic), and \openout or \write18 go further where allowed. The renderer now closes the environment before each occurrence, prints it escaped in \texttt, and reopens it; the api_test case fails without the change.

The latex renderer writes code block contents unescaped between
\begin{verbatim} and \end{verbatim}. LaTeX ends the environment at the
first literal \end{verbatim}, so a code block containing that line
closes it early and the rest of the block is read as TeX. Close the
environment before each occurrence, print it escaped in \texttt, and
reopen it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant