Marking each word in a paragraph


I’m just getting started with ProseMIrror, and the bits I understand I love, but despite the documentation, I’m still finding it hard to work out what I need to do to achieve various things.

My first project is to make an editor that whenever someone makes changes in a block of text, an analysis function runs across the text of the whole block, and marks each word according to the results of the analysis.

I believe that to do this I need a Plugin, so I’ve made a Plugin with an appendTransaction function. To find the block, I create a NodeSelection using the sharedDepth between the from and the to (I got this code from reading the source for the node select button on one of the example editors). Now I’m trying to add marks to each word, but as my first step, I’m just trying to add a mark to the whole node. The selection.from and give plausible numbers, so I return,, newState.doc.type.schema.marks.em). I expected this to make the whole paragraph emphasised, but what actually happens is I get an Uncaught TypeError: n.addToSet is not a function.

I’d be grateful for any help - either on better ways to achieve my goal, or to help me fix whatever I’m doing wrong in this case.


You’re passing a mark type where a mark is expected. Try schema.marks.em.create().


Thanks for that, worked a treat.