sphinx-math-dollar icon indicating copy to clipboard operation
sphinx-math-dollar copied to clipboard

Dollar sign destroys escaping

Open schra opened this issue 2 years ago • 3 comments

Tested sphinx-math-dollar versions: 1.2 and https://github.com/sympy/sphinx-math-dollar/commit/c60310d5038c9864ba85640ac76b7ecf9f8724d5

Exemplary reST code:

Test
----

#. **t**\ est
#. **t**\ est :math:`x`
#. **t**\ est $x$

If you didn't know, **t**\ est sets the first character in bold. In reST you can't just write **t**est like in Markdown.

Rendered output: Screenshot from 2021-09-23 19-42-19

schra avatar Sep 23 '21 17:09 schra

If I had to guess, there is some issue with this nasty regular expression https://github.com/sympy/sphinx-math-dollar/blob/c60310d5038c9864ba85640ac76b7ecf9f8724d5/sphinx_math_dollar/math_dollar.py#L52

asmeurer avatar Sep 23 '21 23:09 asmeurer

Hm, doesn't seem to be the case because if I add the following line to the tests, it works just fine:

assert split_dollars(r"#. **t**\ est $X$") == [("text", r"#. **t**\ est "), ("math", "X")]

The problem is in extension.py. If I replace

        data = split_dollars(str(node).replace('\x00', '\\'))

with

        data = split_dollars(str(node))

then the bug vanishes - however then some math stuff is also rendered weirdly.

I think the problem is that for some reason the \ from the reST is turned into a \0 when we receive the reST in the extension and when we then replace all \0 with a \, we turn the \ into a literal \ and not an escaping sequence.

schra avatar Sep 24 '21 19:09 schra

This has to do with the change from https://github.com/sympy/sphinx-math-dollar/issues/22 (https://github.com/sympy/sphinx-math-dollar/pull/24).

asmeurer avatar Sep 24 '21 20:09 asmeurer