phpDocumentor / phpDocumentor/guides

A :ref: to a label outside a section renders an empty link

Open
#1,394 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
PHP
Stars
36
Forks
22
Avg merge
2d 2h
Merged PRs (30d)
24

Description

AnchorReferenceResolver fills a reference that has no children with $target->getTitle() ?? ''. A target only carries a title when it is a section, or an anchor whose parent in the shadow tree is a SectionNodeCollectLinkTargetsTransformer sets it from $parentSection->getTitle() and leaves it null otherwise. A label declared anywhere else therefore resolves to a link with no text at all.

Minimal reproduction:

..  note::

    .. _nested-label:

    A label declared inside a directive body.

A plain reference to it: :ref:`nested-label`

Rendered with this repository's own default templates at c9868443:

<p>A plain reference to it: <a href="/index.html#nested-label"></a></p>

A resolved link, a correct href, and nothing between the tags. Nothing is logged, because from the resolver's point of view the reference resolved fine. The same page with the label on a section renders <a href="/index.html#section-label">A section with a label</a>, so it is specifically the titleless target that produces the empty link.

Two consequences. For a reader the link is invisible; for a screen reader it has no accessible name at all, which fails WCAG 2.4.4 Link Purpose (In Context) and 4.1.2 Name, Role, Value, both Level A. And since it happens only for labels outside a section, it tends to appear in exactly the places an author reached for a label deliberately.

InterlinkReferenceResolver has the same shape but cannot hit it: InventoryLink::$title is a non-nullable string.

The fix I would suggest is to fall back to the reference the author wrote rather than to the empty string. PR: #1395.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with AnchorReferenceResolver and CollectLinkTargetsTransformer, then reproduce the nested-label example using the repository's default templates. Verify that a titleless target still gets the correct href but uses the written reference as visible and accessible link text, and add or run a regression test for the rendered link.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
accessibility, documentation
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.