Skip to content

🐛 Fix card 🔗 whitespace stripping for ref targets#282

Merged
chrisjsewell merged 1 commit into
mainfrom
fix/card-link-whitespace
Jul 14, 2026
Merged

🐛 Fix card 🔗 whitespace stripping for ref targets#282
chrisjsewell merged 1 commit into
mainfrom
fix/card-link-whitespace

Conversation

@chrisjsewell

@chrisjsewell chrisjsewell commented Jul 14, 2026

Copy link
Copy Markdown
Member

Follow-up to #281: issue #110's literal reproduction used grid-item-card :link: with link-type: ref, and that path was still broken — both card and grid-item-card ran the link option through directives.uri, which deletes all whitespace (my section namemysectionnameundefined label). Notably grid-item-card has its own option spec, verified to need its own fix.

Changes

  • link option becomes unchanged_required; normalization happens in create_card where link-type is known: urldirectives.uri (byte-identical to before — verified across spaces/%20/escapes/tabs), ref → whitespace-collapse + lowercase (parity with the :ref: role and 🐛 Fix button-ref target whitespace and nested content #281's button-ref), doc/any → whitespace-collapse only (case-sensitive targets).
  • The visually-hidden fallback link text now shows the raw value rather than the whitespace-stripped one (cosmetic improvement; nothing asserted the old form).

Behaviour note: a target that only resolved because stripping accidentally matched a spaceless label (e.g. label mysectionname referenced as my section name) no longer resolves — that relied on the bug.

Verification

  • New tests/test_card_link.py (8 tests, rst + myst): multi-word ref targets for both directives (verified red on main with the exact undefined label: 'mysectionname' warnings), Title-Case lowercase parity, URL byte-parity, unresolved-ref degradation.
  • Independent review: URL path byte-identical to main for every URI shape probed; empty-value error behaviour unchanged; no other directives.uri link sites remain; existing card/grid fixtures untouched.
  • Full suite green on pinned Sphinx 7.2.6 / 7.4.7 / 8.2.3 (176 passed each, versions verified in-venv).

Completes the fix for #110

@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.81%. Comparing base (abbf459) to head (ba3f244).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #282      +/-   ##
==========================================
+ Coverage   90.72%   90.81%   +0.09%     
==========================================
  Files          13       13              
  Lines        1207     1219      +12     
==========================================
+ Hits         1095     1107      +12     
  Misses        112      112              
Flag Coverage Δ
pytests 90.81% <100.00%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Both `card` (cards.py) and `grid-item-card` (grids.py, via its own
option_spec) ran the `:link:` option through `directives.uri`, which
deletes all whitespace. For `link-type: ref`, a multi-word target such
as an `autosectionlabel` label (e.g. `my section name`) became
`mysectionname`, producing an `undefined label` warning.

The `link` option is now captured verbatim (`unchanged_required`) and
normalised inside `CardDirective.create_card`, where `link-type` is
known: `url` keeps the `directives.uri` behaviour (byte-identical for
URLs), `ref` collapses whitespace runs and lowercases (matching the
`:ref:` role, `XRefRole(lowercase=True)`), and `doc`/`any` collapse
whitespace but preserve case. Completes the fix for #110 (the
`button-ref` path was fixed in #281).
@chrisjsewell chrisjsewell force-pushed the fix/card-link-whitespace branch from 16949db to ba3f244 Compare July 14, 2026 16:32
@chrisjsewell chrisjsewell merged commit 3adada6 into main Jul 14, 2026
25 checks passed
@chrisjsewell chrisjsewell deleted the fix/card-link-whitespace branch July 14, 2026 21:52
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