How to find all highlights in a given document

Is there a way where you can find all highlights in a document ? Possibly like how kindle shows the highlighted text in a given document ?

Hello Charan,

By highlights, do you mean something like the comments in the Collab Demo?

The pattern is to create a plugin that holds these as Decorations and then read them from the plugin state when you want to process them outside the editor.

Best, Frederik

Hi Frederik ,

Ok . So you mean writing a plugin brings in key values in the prosemirror document json . While persisting it , i will be able to seperately express highlight definition . So while retrieving , i should be able to reach this particular node mark and then show only the content of this particular node with that mark ?

I am still not sure what you mean by highlight, but I am guessing that it is some range of the text that a user has chosen to select and possibly annotate?

I suggest you take a look at how the comment example works.

It keeps the comments in a decoration during editing inside a plugin. This has the advantage that we can automatically update the comment position (lets say if text is entered before the comment, its position is automatically updated).

To persist the Comment the sample implementation remembers the from and to positions in the document as decorations are part of the plugin state and not of the document itself.

I am still not sure whether I understand exactly what you are asking since you mention persisting but also showing these highlights. Maybe you can elaborate a bit or post an example of what you have already done.

Best, Frederik

p.s.: To make the highlight part of the document itself, you can use a mark like the schema uses for em, strong or links ( But this is a decision best based on your actual use case.