I have an API that returns annotations (spelling/grammar/feedback etc.) to decorate a document. My issue is, it gives back each annotation with a line and index (line-based) for the annotation positioning.
Any suggestions on how to map these to my ProseMirror doc?
Its the mapping back of API-provided annotations based on these lines and indexes.
I’m hoping I’m lucky in that the schema is simple, in as much as only having to deal with headings, paragraphs, hard_breaks and lists (unordered/ordered) so the documents are fairly shallow trees to work with.
Since textBetween loses information (non-text structure), I don’t think there’s a way to just map a text position back to a document position. If your schema is extremely simple, or you are willing to do complicated things like matching strings to determine context, you might be able to find a solution, but there’s no simple trick.
With your comments in mind, I’ve ditched textBetween and taken to bend the rules by passing the API one line of text (trying to ignore lines exist) with string fragments whose index should match the doc positioning like so: