-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
sphinx_highlight.js: remove ?highlight= query param handling
#13921
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
Conversation
* 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`
?highlight= query param handling
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.
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 <me@harmenstoppels.nl>
It depends on what you mean by "use". It supports them in so far as if you append It doesn't "use" it in so far as it doesn't show URLs with Until a few years ago, it was added to the URL, and I made a PR for it to be removed when clicking "Hide Search Matches": #9551. Some people didn't like that I still think that this was a mistake and that removing
I don't think it is a decent replacement, since it only highlights the first occurrence, while |
So, If it's for sharing links, then I would argue That to me suggests there's not a good reason to keep the feature. |
Yes, nowadays it is. But previously, it was also there whenever clicking on a search result, which I think was better.
Maybe, but in many cases I'd already see the highlighted text. If not, I'd scroll a bit to see if I find it, and if the page seems too large, I'd probably use Ctrl+F or equivalent.
There might be situation where it's superior, but it might also not be. For example, if the search term is in the middle or end of a paragraph, the beginning of the paragraph might be scrolled out of view. And what if the relevant hit is not the first appearance of the search term? I think the best scenario would be for the search result page to show the sub-sections where the search term occurs, and then a user would click on the right sub-section, most likely arriving at the correct place within the page (Similar to what @jayaddison alluded to in #13916 (comment)). BTW, there are several other objections by @jayaddison in #13916, which we shouldn't forget here.
You are assuming that the first match is the intended one? I think it is preferable to see all possible places (even if it's unclear which is the relevant one) than seeing only one match, which is probably not the relevant one. |
|
NB: I think we can close this as it has been superseded by #13918 which has been merged - thanks, @haampie @AA-Turner. |
Closes #13916
Alternative to #13918
?highlight=query param as a (manual) fallback for search highlighting.While at it:
document.querySelectorAll("div.body")[0]todocument.querySelector("div.body")document.querySelector("body")withdocument.bodysetTimeoutwithrequestAnimationFramePurpose
This PR removes the
?highlight=related code, for two reasons:?highlight=links internally.#:~:text=...is a decent replacement for?highlight=...for adding highlighting manually.window.history.replaceStateunconditionally. 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
<url>?highlight=search-termtolocalStorage.setItem("sphinx_highlight_terms", "search-term")to support highlighting of search terms on a page: Move to localStorage for search highlighting #10854?highlight=...URLs were still supported, cause you could add that manually.?highlight=...was to always remove?highlight=from the URL.sphinx_highlight.jsremoves text fragment from URL #13916window.history.replaceStateunconditionally #13918