Skip to content

Concatenate the text segments of image alt text - #163

Merged
bobzhang merged 1 commit into
mainfrom
conformance/image-alt-text
Oct 2, 2026
Merged

bobzhang merged 1 commit into
mainfrom
conformance/image-alt-text

Conversation

@bobzhang

@bobzhang bobzhang commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Split out of #152. Found by differential fuzzing against markdown-it-py (commonmark preset).

Bug: the HTML renderer joined the plain-text segments of each line of an image description with newlines, and joined the lines with nothing. That is the reverse of what's intended.

Repro: ![foo *bar*](/u) gave alt="foo \nbar". Expected alt="foo bar".

Fix: concatenate the segments of each line, and separate lines (hard breaks) with newlines, reusing joined_string with Iter::join.

Spec examples fixed: 520, 573, 574, 575, 576, 577, 585, 589.

Tests: src/cmark_html/image_alt_text_test.mbt.

Depends on: nothing, independent of the other PRs.

The HTML renderer joined the plain text segments of each line of an
image description with newlines and the lines with nothing, the reverse
of what is intended: `![foo *bar*](/u)` gave alt="foo \nbar" instead of
alt="foo bar" (spec examples 520, 573-577, 585 and 589). Segments are
now concatenated and lines (hard breaks) separated by newlines.
@bobzhang

bobzhang commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

Automated review: Codex CLI (codex exec, model reasoning effort high, read-only sandbox), 1 round, on git diff against the base branch.

Verdict: signed off, no changes requested.

I sign off on the code change. No concrete correctness or regression issues found.

The fix concatenates inline segments and preserves hard-break boundaries, consistent with CommonMark 0.31.2’s image-description guidance. HTML escaping remains intact, and Iter::join is appropriate. The tests cover the reported bug, nested links/images, and hard breaks.

Codex could not run moon test in its read-only sandbox. The tests were run separately on native, js and wasm-gc and pass.

@bobzhang
bobzhang merged commit 7ab3f4c into main Oct 2, 2026
9 checks passed
@bobzhang
bobzhang deleted the conformance/image-alt-text branch October 2, 2026 01:41
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.

1 participant