Treora commented on issue #60: URL: https://github.com/apache/incubator-annotator/issues/60#issuecomment-722659798
We shortly discussed this topic in today’s call while looking over the open issues. We agreed that just parsing the syntax is not much use, as it comes together with a specific algorithm for finding the target text, which differs from the Web Annotation model. A quick overview of things we could provide: - anchoring of a fragment directive: I implemented the essence of this already (see above comment); we could provide a function that simply wraps my implementation. (we even discussed the option of importing my whole implementation into this repo, though to me it feels cleaner to keep these as separate projects) - describing a selection (a Range or perhaps a list of Ranges) as a fragment directive: this would need a custom adaptation of `describeTextQuote`, modified to ensure that the total quote (including prefix&suffix) ends at word boundaries (note that at least this is possible now, since a recent [change][] in the spec). Also, it should use a `textStart,textEnd` pair (again to be cut at word boundaries) instead of an exact quote when the selection crosses block elements. And perhaps there are more hurdles. - convert fragment directive ⇒ Selector: If the document is available, we could simply anchor it and describe it in the other format. Without the document at hand, we could also convert it, although with a (hopefully small) risk that the differences in specifications will make it fail to anchor or (worse) point at something else. I think the conversion could, after syntax parsing, be done with more or less this simple code: ``` ({ prefix, textStart, textEnd, suffix }) => textEnd ? { type: 'RangeSelector', start: { type: 'TextQuoteSelector', prefix, exact: textStart }, end: { type: 'TextQuoteSelector', prefix: textEnd, exact: '', suffix } } : { type: 'TextQuoteSelector', prefix, exact: textStart, suffix } ``` (note the little hack of using `prefix: textEnd, exact: ''` because RangeSelector’s end is exclusive and `textEnd` should nevertheless be included in the target) - convert Selector ⇒ fragment directive: the reverse of the above. Again, if the document is available, we could simply anchor it and describe it in the other format. But in case the document is not available, conversion in this direction would only possible if the selector is of the type/shape shown in the above example code. I suppose it is mainly a matter of demand and priority whether we’ll implement any of these. I might actually try tackle some of these points soon, as I would like to use these features myself. [change]: https://github.com/WICG/scroll-to-text-fragment/pull/148 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org