diff --git a/myst_parser/mdit_to_docutils/base.py b/myst_parser/mdit_to_docutils/base.py index a275cd71..6aac6a48 100644 --- a/myst_parser/mdit_to_docutils/base.py +++ b/myst_parser/mdit_to_docutils/base.py @@ -504,10 +504,11 @@ def renderInlineAsText(self, tokens: list[SyntaxTreeNode]) -> str: # noqa: N802 result = "" for token in tokens or []: - if token.type == "text": + if token.type in {"text", "text_special"}: + # An escape or entity is a text_special token with no children. + # Its content is the character the alt text must keep + # (executablebooks/MyST-Parser#1210). result += token.content - # elif token.type == "image": - # result += self.renderInlineAsText(token.children) else: result += self.renderInlineAsText(token.children or []) return result diff --git a/tests/test_renderers/fixtures/docutil_syntax_elements.md b/tests/test_renderers/fixtures/docutil_syntax_elements.md index 9b12b60f..2ab785f4 100644 --- a/tests/test_renderers/fixtures/docutil_syntax_elements.md +++ b/tests/test_renderers/fixtures/docutil_syntax_elements.md @@ -190,6 +190,44 @@ Image with escapable html: alt . +Image alt with escapes and entities: +. +![a \* b & C:\Python26](x.png) +. + + + a * b & C:\Python26 +. + +Image alt with escapes and entities in emphasis: +. +![a *\* b ©*](x.png) +. + + + a * b © +. + +Image alt with an escape in a nested image: +. +![outer ![in\*ner](y.png)](x.png) +. + + + outer in*ner +. + +Image alt with an escape, reference style: +. +![a \* b][r] + +[r]: x.png +. + + + a * b +. + Block Quote: . > *foo*