-
Notifications
You must be signed in to change notification settings - Fork 225
This is a feature request for text fragment URL support with Hypothesis.
Text fragment URL is an extension to URL scheme which allows to attach a text to an URL hash so that when a user clicks on the URL the attached text appears as highlighted and the window scrolls to the highlighted text.
The syntax of text fragment URL is as follow: #:~:text=[prefix-,]textStart[,textEnd][,-suffix] and matches the Hypothesis one for the TextQuoteSelector annotation except it contains an optional textEnd parameter.
Generating a text fragment is not easy, as you can see when testing by using the Copy link to highlight capability with Chrome: depending on the position of the selection, the text fragment can be completely different from another one close to it. There's a text-fragment-polyfill which gives an idea of how complicated it is, by handling different cases based on the HTML element e.g.
The text-fragment-polyfill generates a text fragment hash based on a window.selection - I can't seem to find a way to generate a text fragment URL using solely Hypothesis TextQuoteSelector prefix, exact and suffix text parts that would match the result of the polyfill.
So it would make sense to generate the text fragment URL with the client bookmarklet at the same moment the user highlights the text and creates an annotation.
The annotation object would contain a new field with the hash text fragment.
And on Hypothesis pages, the resource URL would contain the text fragment hash in it so that when the user clicks on it, highlights would be displayed on the opened page immediately without requiring to load the client bookmarklet.
It's possible to attach multiple text fragments to an hash URL by separating them with an ampersand character &, so when clicking on a resource URL the user can see all of their highlights at once.