What version of myst-parser are you using?
5.1.0
What version dependencies are you using?
- markdown-it-py
4.2.0
- docutils
0.22.4
- Python
3.14.7
What operating system are you using?
Mac
Describe the Bug
The alt attribute of an image loses every backslash escape and every entity of its alt text:  gives alt="C:ython26".
renderInlineAsText reads text tokens only. An escape or an entity inside an image is a text_special token with no children:
|
def renderInlineAsText(self, tokens: list[SyntaxTreeNode]) -> str: # noqa: N802 |
|
"""Special kludge for image `alt` attributes to conform CommonMark spec. |
|
|
|
Don't try to use it! Spec requires to show `alt` content with stripped markup, |
|
instead of simple escaping. |
|
""" |
|
result = "" |
|
|
|
for token in tokens or []: |
|
if token.type == "text": |
|
result += token.content |
|
# elif token.type == "image": |
|
# result += self.renderInlineAsText(token.children) |
|
else: |
|
result += self.renderInlineAsText(token.children or []) |
|
return result |
markdown-it 15.0.0 fixed the token side: markdown-it/markdown-it@974e2d7 makes text_join convert those tokens to text inside image alt text. markdown-it-py 4.2.0 does not have that change.
Expected Behavior
alt="a * b", alt="a & b" and alt="C:\Python26".
To Reproduce
from docutils.core import publish_parts
from myst_parser.parsers.docutils_ import Parser
for src in (
r"",
"",
r"",
r"[a \* b & c](https://example.com)",
):
print(publish_parts(src, parser=Parser(), writer_name="html5")["body"], end="")
Output:
<p><img alt="a b" src="x.png" /></p>
<p><img alt="a b" src="x.png" /></p>
<p><img alt="C:ython26" src="x.png" /></p>
<p><a class="reference external" href="https://example.com">a * b & c</a></p>
What version of
myst-parserare you using?5.1.0
What version dependencies are you using?
4.2.00.22.43.14.7What operating system are you using?
Mac
Describe the Bug
The
altattribute of an image loses every backslash escape and every entity of its alt text:givesalt="C:ython26".renderInlineAsTextreadstexttokens only. An escape or an entity inside an image is atext_specialtoken with no children:MyST-Parser/myst_parser/mdit_to_docutils/base.py
Lines 453 to 468 in 2871eb9
markdown-it15.0.0fixed the token side: markdown-it/markdown-it@974e2d7 makestext_joinconvert those tokens totextinside image alt text.markdown-it-py4.2.0does not have that change.Expected Behavior
alt="a * b",alt="a & b"andalt="C:\Python26".To Reproduce
Output: