Skip to content

🐛 FIX: emit unresolved cross-references as external links - #1246

Open
draarivpatel-ui wants to merge 1 commit into
executablebooks:masterfrom
draarivpatel-ui:fix/unresolved-xref-external-link
Open

draarivpatel-ui wants to merge 1 commit into
executablebooks:masterfrom
draarivpatel-ui:fix/unresolved-xref-external-link

Conversation

@draarivpatel-ui

Copy link
Copy Markdown

Fixes #1245

Problem

A myst reference that no domain, inventory or local anchor can resolve is emitted as a reference node carrying refid:

newnode["refid"] = normalizeLink(target)

refid is a document-local id reference, so HTML writers render it as a fragment link into the current page. In a project with files a.md and b.md, writing [broken](b1.md) in a.md produces:

<a class="reference internal" href="#b1.md"><span class="xref myst">broken</span></a>

href="#b1.md" is a fragment link that can never resolve, while the documentation and the comment above the line both say the destination is left as an external link.

Fix

Use refuri for the fallback reference, so the authored destination is kept as the link target:

<a class="reference external" href="b1.md"><span class="xref myst">broken</span></a>

The myst.xref_missing warning is unchanged, so authors still learn at build time that the target does not exist.

Tests

  • New regression test test_unresolved_target_degrades_to_external_link covering the exact reported scenario ([broken](missing.md)), asserting the warning fires and the reference is refuri based, not refid.
  • Regenerated the two fixtures that pinned the fragment-link output (test_parse[missing], test_references); both now show the documented external-link fallback.
  • Full test suite passes locally: 919 passed + 646 commonmark, ruff clean.

A 'myst' reference that no domain, inventory or local anchor could
resolve was emitted as a reference with a refid, which HTML writers
render as a local fragment link (href="#target"). The documented
fallback is an external link that keeps the authored destination, so
[broken](missing.md) produced href="#missing.md" instead of
href="missing.md".

Use refuri for the fallback reference and add a regression test.

Fixes executablebooks#1245
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

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.

Incorrect crossreference links generate local fragment-links

2 participants