🐛 FIX: render hardbreak and inline HTML in image alt text#409
Open
chuenchen309 wants to merge 1 commit into
Open
🐛 FIX: render hardbreak and inline HTML in image alt text#409chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
`RendererHTML.renderInlineAsText`, used to build image `alt` attributes, only handled `text`, `image` and `softbreak` tokens and silently dropped `hardbreak`, `html_inline` and `html_block`. The upstream markdown-it JS reference this port targets (v14.1.0) handles all of these, and `softbreak`/`hardbreak` are treated as a pair everywhere else in the codebase, so a hard line break or inline HTML in an image description was lost from the alt text (e.g. `` produced `alt="foobar"` instead of `alt="foo\nbar"`). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: chuenchen309 <48723787+chuenchen309@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
RendererHTML.renderInlineAsTextbuilds thealtattribute for images by walking the inline token stream, but it only handlestext,imageandsoftbreaktokens.hardbreak,html_inlineandhtml_blockare silently dropped, so a hard line break or inline HTML inside an image description disappears from the alt text.Why this is the intended behaviour
Two independent references, both pointing the same way:
markdown-itand the changelog pins the parser tomarkdown-it v14.1.0. UpstreamrenderInlineAsTextat that version handlestext,image,html_inline,html_block,softbreakandhardbreak. The Python port is behind its own declared target for the last three.softbreakandhardbreakare treated as an identical pair everywhere else in the codebase; 🐛 FIX: Newline not rendered in image alt attribute #157 previously added thesoftbreakbranch to this very function but stopped there. This change is the sibling of that fix.HTML content in
altis escaped downstream byrenderAttrs→escapeHtml(so<b>becomes<b>), matching the JS behaviour — no markup reaches the attribute unescaped.The fix
Two grouped branches added to
renderInlineAsText, making it a 1:1 match of the upstream reference:Verification
tests/test_port/fixtures/commonmark_extras.md(hard break and inline HTML in an image description), mirroring the existing 🐛 FIX: Newline not rendered in image alt attribute #157 soft-break fixture. Both fail without the change and pass with it.renderInlineAsTexthas a single production caller (theimagerenderer), and the soft-break / plain-text paths are unchanged (verified as controls).pre-commitruff, ruff-format and mypy (strict) all clean.This PR was authored by an AI coding agent (Claude Code) running on this account: the AI found the bug, ran the repro, wrote the tests, and wrote this description. The human account holder reviews every change and is accountable for it. The verification above is real and re-runnable from the diff. If this isn't the kind of contribution you want, say so and I'll close it.