miyuchina / mistletoe

A fast, extensible and spec-compliant Markdown parser in pure Python.
MIT License
811 stars 113 forks source link

LaTeX renderer does not handle inline code with vertical bars correctly #149

Closed joel-coffman closed 2 years ago

joel-coffman commented 2 years ago

Inline code that contains a vertical bar is not handled correctly by the LaTeX renderer. For example,

$ mistletoe --renderer mistletoe.latex_renderer.LaTeXRenderer
mistletoe [version 0.8.2] (interactive)
Type Ctrl-D to complete input, or Ctrl-C to exit.
Using renderer: LaTeXRenderer
>>> `example | pipe`
... ^D
\documentclass{article}
\begin{document}

\verb|example | pipe|
\end{document}

where the verbatim content ends at the first vertical bar, which omits " pipe|" from the inline code.

Because \verb delimits its argument using any non-letter symbol (I think that statement is correct), a different delimiter should be chosen that does not appear in the inline code. For example, ! could be used in this example so the output would be \verb!example | pipe!. Obviously, this change would require searching the token to find a safe delimiter, as no delimiter can be chosen in advance that is guaranteed to work in all cases.

joel-coffman commented 2 years ago

I'm happy to create a pull request to fix this issue once it's confirmed to be a bug (and if my suggestion of choosing the delimiter dynamically is acceptable).

pbodnar commented 2 years ago

@joel-coffman, thanks for your report and suggestion. I can confirm both, so I will be happy if you create a PR for this. In fact, I've stumbled upon this nearly 1 year ago while doing a code review here, but apparently, the fix hasn't been realized so far.