miyuchina/mistletoe

LaTeX renderer does not handle inline code with vertical bars correctly

Closed this issue · 2 comments

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.

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).

@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.