-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
Description
Describe the bug
All major browsers support highlighting with Text Fragments, which is the #:~:text=... bit in a URL:
It highlights and scrolls to the first match on the page, which is extremely useful. It's used by Google Search to scroll to a particular part of the page, and by LLMs to link to a relevant bit of the page they got their answers from, which is super useful these days.
Annoyingly, Sphinx's sphinx_highlight.js always removes this text fragment from the URL, making sharing of the exact URL the user found impossible.
How to Reproduce
Go to
Notice that the URL bar is immediately replaced with
https://www.sphinx-doc.org/en/master/usage/quickstart.html
instead of the original
https://www.sphinx-doc.org/en/master/usage/quickstart.html#:~:text=In%20Sphinx%20source
Presumably this is due to
| window.history.replaceState({}, "", url); |
which is run unconditionally from
| if (typeof Search === "undefined") SphinxHighlight.highlightSearchWords(); |