Skip to content

feat: ensure every rendered <img> has an alt attribute (a11y) - #10

Merged
JohannesHoppe merged 1 commit into
mainfrom
fix/ensure-img-alt
Jul 23, 2026
Merged

feat: ensure every rendered <img> has an alt attribute (a11y)#10
JohannesHoppe merged 1 commit into
mainfrom
fix/ensure-img-alt

Conversation

@JohannesHoppe

@JohannesHoppe JohannesHoppe commented Jul 23, 2026

Copy link
Copy Markdown
Member

Problem

Images reach the generated HTML two ways:

  • Markdown images ![alt](img.png) — the imageRenderer always emits an alt (even an empty one).
  • Manual raw <img> tags — authored directly in the Markdown, these frequently have no alt and only pass through transformRelativeImagePaths (which rewrites src only).

A missing alt makes screen readers announce the image's file name — an accessibility gap on any post that hand-writes an <img>.

Fix

Add ensureImageAlt() in shared/html.utils.ts and apply it late — as the final step in compileMarkdown() on the fully transformed HTML — so both image sources are covered uniformly:

  • <img> without any alt → gets a decorative alt="".
  • <img> that already has an alt (including alt="") → left untouched.

Applying it late (rather than in the image renderer) is deliberate: the renderer only sees Markdown images, while raw <img> bypass it. Running once on the final HTML catches every image regardless of how it was written.

Images reach the HTML two ways: Markdown images (the renderer already emits an
alt, even an empty one) and manual raw <img> tags, which frequently lack alt. A
missing alt makes screen readers announce the file name.

Add ensureImageAlt() and apply it LATE - as the final step in compileMarkdown()
on the fully transformed HTML - so both image sources are covered uniformly.
Images that already carry an alt (including alt="") are left untouched.

Adds unit tests for ensureImageAlt plus parser integration tests proving a raw
<img> without alt gets alt="" while an existing alt is preserved.
@JohannesHoppe
JohannesHoppe merged commit dba6905 into main Jul 23, 2026
1 check passed
@JohannesHoppe
JohannesHoppe deleted the fix/ensure-img-alt branch July 23, 2026 10:54
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