CrossNox / m2r2

Markdown to reStructuredText converter
https://crossnox.github.io/m2r2
MIT License
107 stars 26 forks source link

Support gitlab-style inline math $`a=b`$ #20

Open kalvdans opened 3 years ago

kalvdans commented 3 years ago

Since https://github.com/miyakogi/m2r/commit/eeb618b9e5a3c59b90e4c5ac92df0703c57ac76a m2r supports inline math with dollar signs inside backticks, but gitlab uses backticks inside dollar signs.

We would like to render the same document with gitlab and with sphinx, and so would like m2r2 to support the gitlab way.

kalvdans commented 1 year ago

Since 15.5 gitlab supports inline math surrounded by only dollar signs only: https://gitlab.com/gitlab-org/gitlab/-/issues/21757

Their regular expression to avoid treating currencies as math is here

alexisthual commented 1 year ago

I agree with @kalvdans and think that m2r2 should consider that inline math will be using $...$ instead of `$...$`since it has become the expected behaviour on github and gitlab. This is a blocker for me now as it prevents me from importing a readme.md file used to describe a github package in this package's documentation.

I guess in essence, all it takes is to change this line https://github.com/CrossNox/m2r2/blob/0408d7acea843485d9ff42ee08a105a79f045493/m2r2.py#L122 to

inline_math = re.compile(r"\$(.*?)\$")

and then adapt the tests.

What do you think @CrossNox ? :blush: Thanks for the great package anyways!

milannnnn commented 1 year ago

Any news regarding this issue?

kalvdans commented 1 year ago

Any news regarding this issue?

No work done yet, but any time soon I'll do a pull request to support the new style with only dollar signs. It is in the backlog at my workplace.

kalvdans commented 1 year ago

Pull request up at https://github.com/CrossNox/m2r2/pull/62; please try it out @milannnnn and @alexisthual!

We hit https://gitlab.com/gitlab-org/gitlab/-/issues/389949 preventing some expressions to render correctly in gitlab; the generated mathjax with m2r2 + sphinx looks ok though.

You can get the PR backported to v0.3.2 by writing this in your requirements.txt:

git+https://github.com/Orexplore/m2r2.git@single-dollar-style-math-v0.3.2