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
@chrisjsewell

Copy link
Copy Markdown
Member

Merged in 2787da1, thanks @jayhemnani9910! This is markdown-it 15.0.0's change (markdown-it/markdown-it#1142). Before merging I pushed a few commits on top:

  • merges of master, the last one resolving the fixture overlap with 🐛 Keep backslash escapes and entities in image alt text #446 and adding a combined case (![a \* `c<d` &amp; e](/u) gives alt="a * c&lt;d &amp; e");
  • a fixture with a < in the code span, checking that the text is escaped in the attribute;
  • upstream's own fixture for this change, in commonmark_extras.md.

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