-
-
Notifications
You must be signed in to change notification settings - Fork 249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Certain characters in markdown code incorrectly parsed (e.g., &) #394
Comments
Okay, I've taken a closer look. TL;DR: we need to move the call to This is another case of HTML-escaping being applied in the parse stage, instead of during HTML rendering, resulting in HTML-specific escapes leaking into non-HTML outputs/uses: >>> md = mistune.Markdown()
>>> md('[hi](https://example.com/xyz?a=b&foo=bar)')
[{'type': 'paragraph', 'children': [{'type': 'link', 'children': [{'type': 'text', 'raw': 'hi'}], 'attrs': {'url': 'https://example.com/xyz?a=b&foo=bar'}}]}] (The same kind of issue as for inline code spans - different code paths, but same abstract "shape".) The current logic of PR soon. |
Thanks a lot for this elaborate analysis and the reproducible example. I was indeed expecting the |
I encountered a similar issue as #372, originally found in omnilib/sphinx-mdinclude#19. I did some digging and found that the issue lays in
mistune.util.escape_url
indeed as @torokati44 points towards, but only because its behavior is different depending on whetherhtml
is installed (this happens in the import, at least of mistune 2.0.5):mistune/mistune/util.py
Lines 22 to 31 in cb580e8
Some code to reproduce:
This gives different results. The first one is returned if
html
is not installed, the second one ifhtml
is installed. The third one is correct again:Therefore, what I think should fix the issue is to remove the
html.escape()
from theescape_url
function so the behaviour is always consistent and according to expectations.Update for newer mistune versions
The
escape_url
function looks different in the master branch (>3.0.0):mistune/src/mistune/util.py
Lines 32 to 39 in 93fd197
In this case omitting
escape
does the trick.Originally posted by @veenstrajelmer in #372 (comment)
The text was updated successfully, but these errors were encountered: