Skip to content

🐛 Keep code span text in image alt text - #460

Merged
chrisjsewell merged 6 commits into
executablebooks:masterfrom
jayhemnani9910:fix-alt-code-inline
Nov 9, 2026
Merged

chrisjsewell merged 6 commits into
executablebooks:masterfrom
jayhemnani9910:fix-alt-code-inline

Conversation

@jayhemnani9910

Copy link
Copy Markdown
Contributor

renderInlineAsText skips code_inline tokens, so a code span in an image description vanishes from the alt attribute:

>>> from markdown_it import MarkdownIt
>>> MarkdownIt("commonmark").render("![a `code` b](x.png)")
'<p><img src="x.png" alt="a  b" /></p>\n'

markdown-it 15 gives alt="a code b", and the CommonMark spec keeps the plain text of the description. Upstream's renderInlineAsText handles code_inline together with text; this does the same.

I ran markdown-it 15.0.3 and markdown-it-py 4.2.0 (commonmark preset) over about 3000 Markdown files from real projects; this was the only difference in the output.

Tests: new case in tests/test_port/fixtures/issue-fixes.md, which fails without the change. pytest with the linkify and plugins extras: 1033 passed.

(Add a CHANGELOG line under Unreleased once the PR number is known, like the other entries.)

@chrisjsewell
chrisjsewell merged commit 2787da1 into executablebooks:master Nov 9, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants