Skip to content

Fix hyperlink target detection in URL wrapping - #394

Draft
jum-apzn wants to merge 1 commit into
PyCQA:masterfrom
jum-apzn:fix-hyperlink-target-detection
Draft

jum-apzn wants to merge 1 commit into
PyCQA:masterfrom
jum-apzn:fix-hyperlink-target-detection

Conversation

@jum-apzn

@jum-apzn jum-apzn commented Oct 9, 2026

Copy link
Copy Markdown

Fixes #269.

The malformed prefix alternative in URL_REGEX excludes explicit reST hyperlink targets. A long target can consequently be split away from its URL, producing invalid markup.

This separates the inline-link and explicit-target alternatives, restores periods in inline labels, and keeps the target underscore mandatory. The angle-bracket lookahead prevents an earlier reference from being consumed with a later anonymous URL, preserving the behavior covered by #75 and #210.

Adds 18 parametrized cases covering complete link spans, non-link text, unrelated markup, long targets at module/function indentation, and formatting idempotence. Seven of those cases fail before the fix.

Validation on Python 3.12.14:

  • Full pytest suite: 621 passed, 3 skipped
  • 24 additional CLI preservation/idempotence checks
  • Black, Ruff, isort, mypy, pydocstyle, docformatter, and git diff --check passed

Related prior work: #324 included a similar regex correction in a broader change; this keeps the fix focused on #269 with regression coverage.

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.

I believe URL_REGEX is missing a |

1 participant