Describe the bug
All major browsers support highlighting with Text Fragments, which is the #:~:text=... bit in a URL:
https://www.sphinx-doc.org/en/master/usage/quickstart.html#:~:text=In%20Sphinx%20source
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
https://www.sphinx-doc.org/en/master/usage/quickstart.html#:~:text=In%20Sphinx%20source
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(); |
Describe the bug
All major browsers support highlighting with Text Fragments, which is the
#:~:text=...bit in a URL:https://www.sphinx-doc.org/en/master/usage/quickstart.html#:~:text=In%20Sphinx%20source
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.jsalways removes this text fragment from the URL, making sharing of the exact URL the user found impossible.How to Reproduce
Go to
https://www.sphinx-doc.org/en/master/usage/quickstart.html#:~:text=In%20Sphinx%20source
Notice that the URL bar is immediately replaced with
instead of the original
Presumably this is due to
sphinx/sphinx/themes/basic/static/sphinx_highlight.js
Line 84 in eaebbec
which is run unconditionally from
sphinx/sphinx/themes/basic/static/sphinx_highlight.js
Line 153 in eaebbec