Skip to content

fix(markdown): do not underline whitespace around linked images - #3236

Open
tmoreiradev wants to merge 1 commit into
primer:mainfrom
tmoreiradev:fix/markdown-linked-image-underline
Open

tmoreiradev wants to merge 1 commit into
primer:mainfrom
tmoreiradev:fix/markdown-linked-image-underline

Conversation

@tmoreiradev

Copy link
Copy Markdown

Fixes #3128.

.markdown-body underlines the line break and indentation that sit between <a> and <img> when the pair is authored as nested HTML on separate lines — which is how badge rows inside <p align="center"> have to be written. The whitespace is a text node inside the link, inherits its text-decoration, and paints as an underlined gap on both sides of the badge.

The anchor that wraps an image and nothing else becomes a flex container, so the whitespace-only children are dropped and there is nothing left to underline:

a[href]:has(> img) {
  display: inline-flex;
}

Notes:

  • Scoped with > img so links with text and an image keep normal inline flow.
  • Spacing between adjacent badges is unaffected: that whitespace is between anchors, not inside them.
  • :has() is baseline in every browser that still gets .markdown-body styles; no fallback needed.
  • Verified locally: script/build-css.js emits .markdown-body a[href]:has(>img){display:inline-flex} and npx stylelint src/markdown/images.scss is clean (only the two pre-existing value-no-unknown-custom-properties warnings elsewhere in the file).
  • Changeset added (patch).

Credit to @rich-ayr, who wrote up the reproduction and the proposed rule in the issue.

@tmoreiradev
tmoreiradev requested review from a team as code owners November 19, 2026 05:42
@changeset-bot

changeset-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 585a2f1

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/css Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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.

.markdown-body: whitespace inside <a> wrapping <img> renders as underlined space

1 participant