-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check for targets prefixed with user-content- #12702
Conversation
sphinx/builders/linkcheck.py
Outdated
@@ -630,21 +633,6 @@ class RateLimit(NamedTuple): | |||
next_check: float | |||
|
|||
|
|||
def rewrite_github_anchor(app: Sphinx, uri: str) -> str | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should still use this, rather than attempting to insert 'user-content-' for every website.
@madmiraal thanks for the pull request! Similar to @AA-Turner, I'm wary of applying a change to handle a few websites that affects all websites - it's tricky to roll those kind of changes back. This one seems fine, but even so let's figure out what we can figure out. From some digging around on the web: it seems that the Thinking about what this change does: its transforming Thinking aloud: what if instead we emitted a warning and a |
sphinx/builders/linkcheck.py
Outdated
@@ -630,21 +633,6 @@ class RateLimit(NamedTuple): | |||
next_check: float | |||
|
|||
|
|||
def rewrite_github_anchor(app: Sphinx, uri: str) -> str | None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please note: some people may still be using rewrite_github_anchor
in their Sphinx project configurations. We should add a deprecation notice to the function instead of removing it completely, so that they have time to adjust. Features are removed two major versions after they are first indicated for removal (so Sphinx v10.0 for this).
More information about this can be found in Sphinx's deprecation policy documentation: https://www.sphinx-doc.org/en/master/internals/release-process.html#deprecation-policy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the PR to add a deprecation message to rewrite_github_anchor
instead of deleting it.
Thanks for all the feedback.
I agree that this may lead to some false positives, but I think these will be insignificantly few, and there will be many websites using Gitea that would benefit from this too. However, we could add an option defaulting to
The problem is: the un-prefixed target is the correct one. It is the one provided; so it's what people would expect to work:
Please correct me if I am wrong, but from what I can tell, sphinx/sphinx/builders/linkcheck.py Line 688 in b0485f9
How else would people use it that we would need to mark it as deprecated? |
That's the root cause, yep - sites presenting shortened/prettified hyperlinks that act like standard navigation (browser location on page) and yet aren't referencing the corresponding HTML content.
After verifying your example from sphinx.builders.linkcheck import rewrite_github_anchor
def setup(app):
app.connect('linkcheck-process-uri', rewrite_github_anchor) (in other words: yep, it's commented out, meaning that it isn't enabled by default, but it is still available for usage) The |
For now, let's use the site-specific filter with GitHub and perhaps GitLab. If people want to use this with Gitea we will get feature requests, but let's start simple (without another config option!) A |
@jayaddison please could I test something with you? I've updated the repository settings to give members of the triage team more permissions on GitHub.
A |
961aa32
to
2a4ef91
Compare
2a4ef91
to
9ece45d
Compare
Thanks @AA-Turner - I'll likely only use the second permission very sparingly, but yep, I can confirm that all three permissions/restrictions are in place as expected:
|
I'm not convinced that making a site-specific filter is maintainable. In addition to Gitea, GitLab is also used by a number of sites that don't use the That been said, I've tested this with a number of Github type sites:
Unfortunately, neither this approach nor the original Therefore, I'm closing this PR in lieu of finding a more comprehensive solution. |
When looking for anchors, check for targets prefixed with
user-content-
.Feature or Bugfix
Purpose
When parsing user
.md
and.rst
files, GitHub, GitLab and Gitea automatically createhref
fragment targets to headings. To avoid DOM clobbering they appenduser-content-
to the automatically createdname
andid
targets and use JavaScript to manually scroll to the heading when the URL contains the un-prefixed fragment. Since prefixing targets withuser-content-
is the de facto standard, to avoidlinkcheck.py
failing to find the un-prefixed anchors, we need to also check for targets prefixed withuser-content-
when parsing the HTML looking for a URL's fragment.Detail
Using Sphinx's own
README.rst
, we can reference the Features section using https://github.com/sphinx-doc/sphinx#features.However, when testing this reference with:
index.rst
:conf.py
: emptyRunning linkcheck:
Without this PR, it fails:
With this PR, it succeeds:
Note: this does not reintroduce regression #9435, because
linkcheck.py
currently fails with these#Lxxx
fragments. The#Lxxx
fragments only work with JavaScript. There are no prefixedLxxx
name
andid
targets.Relates