How should we mark ranges of text unique identifiers?

Marked ranges seem similar to a doc.markText in Codemirror. As I understand it, the mark text will be lost when saving the document, so one needs to save all the marked text ranges at the time of document saving and then restore them when the document is loaded, correct? Also, I would want to attach an ID or data attributes so that I can attach click events, find their on-screen position, etc. . I think I saw somewhere in some thread that you mentioned that if one hands an unknown option name to markText, it will turn into an attribute of the DOM element that will be used to style the marked text. Is this correct and is this also the way to do it in Prosemirror?

One of the use cases for this is threaded commenting system where the comments are displayed to the right of the document but as far as possible are aligned vertically to the text they are referring to. Similar to many of the standard word processors. The commenting system probably has to be independent of the text editor, but it would be good if one could refer to such an identifier in order to move the comment if the text it refers to moves. Also, when a user clicks on a comment, it could highlight the part of the text that the comment refers to, etc.

Yes.

You’ll find the object you pass as 3rd argument to markRange in the options property of the marker object that it returns. (The CodeMirror approach is a bit of an accidental messy hack.) You definitely won’t get DOM attributes. For now, you’ll have to get the click position, and iterate to your own list of ranges to figure out if it is inside of one. Again, see the website’s collaborative demo for an example.