Skip to content

Conversation

haampie
Copy link
Contributor

@haampie haampie commented Sep 30, 2025

Closes #13916

Alternative to #13918

  • Remove support for ?highlight= query param as a (manual) fallback for search highlighting.

While at it:

  • Simplify document.querySelectorAll("div.body")[0] to document.querySelector("div.body")
  • Simplify document.querySelector("body") with document.body
  • Replace setTimeout with requestAnimationFrame

Purpose

This PR removes the ?highlight= related code, for two reasons:

  1. Sphinx does not use ?highlight= links internally.
  2. Browser native support for Text Fragments #:~:text=... is a decent replacement for ?highlight=... for adding highlighting manually.
  3. The current logic runs window.history.replaceState unconditionally. This has an unpleasant side effect: it removes #:~:text=... fragments from the URL, making it hard to purposefully share URLs that include highlighted text.

References

* Do not use `?highlight=` query param as a fallback for search
  highlighting. All major browsers support `#:~:text=` natively now, and
  Sphinx does not link from search results with `?highlight=` URLs, it
  only uses `localStorage`.
* Simplify `document.querySelectorAll("div.body")[0]` to
  `document.querySelector("div.body")`
* Simplify `document.querySelector("body")` with `document.body`
* Replace `setTimeout` with `requestAnimationFrame`
@haampie haampie changed the title sphinx_highlight.js: remove highlight query param handling sphinx_highlight.js: remove ?highlight= query param handling Sep 30, 2025
haampie added a commit to spack/spack that referenced this pull request Oct 7, 2025
Use Sphinx 8.2.3 with this patch:
sphinx-doc/sphinx#13921, so that it's easier to
link particular paragraphs in the text using Text Fragments.
haampie added a commit to spack/spack that referenced this pull request Oct 7, 2025
Use Sphinx 8.2.3 with this patch:
sphinx-doc/sphinx#13921, so that it's easier to
link particular paragraphs in the text using Text Fragments.

Signed-off-by: Harmen Stoppels <[email protected]>
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.

sphinx_highlight.js removes text fragment from URL

1 participant