Skip to content

Conversation

haampie
Copy link
Contributor

@haampie haampie commented Sep 27, 2025

Closes #13916

Currently every Sphinx documentation page always drops #:~:text=... Text Fragments unconditionally due to a window.history.replaceState() call.

That's undesirable, because it prevents users from sharing the URL verbatim including the text fragment. Text fragments are increasingly popular these days as they're used by Google Search and various LLMs to scroll to and highlight specific content on a longer page.

The solution is to only call window.history.replaceState when a Sphinx's custom ?highlight=... search param is part of the URL.

Currently every Sphinx documentation page *always* drops `#:~:text=...` Text Fragments unconditionally due to `window.history.replaceState`.

The solution is to only call `window.history.replaceState` when a `?highlight=...` param is part of the URL.
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