how to disable \ escaping?
sixwaaaay opened this issue · 1 comments
When using the markdownify function to process strings, I expect the output to preserve the raw string without escaping backslashes \ . For example:
Code Example:
from markdownify import markdownify as md
print(md(r"\rm b"))
print(md(r"$ \rm b $"))
print(md(r"$ \rm b $"))Actual Output:
\\rm b
$ \\rm b $
$ \\rm b $
Expected Output:
\rm b
$ \rm b $
$ \rm b $
Problem
the function appears to escape backslashes, resulting in extra \ in the output. This behavior is problematic for input with latex code.
When rendering the actual output
\\rm b
$ \\rm b $
$ \\rm b $we get:
\rm b
$ \rm b $
$ \rm b $
which is correct. The goal of this lib is to produce Markdown that renders the input as it was displayed in HTML. According to https://daringfireball.net/projects/markdown/syntax#backslash rendering a \ requires it to be escaped by another \.
You could post-process your output by replacing every occurance of \\ with \:
r"$ \\rm b $".replace(r"\\", "\\")