Is there a way to preserve text formatting with empty text content?

Is there any way to preserve arbitrary formats (bold, font size, etc) when you don’t have text in the node?

For example, if I initialize an editor with the HTML <p><strong></strong></p>, when the user focuses and starts typing, I want the text to already be bold. Right now, it just ignores the empty strong tag.

Does storedMarks meets your requirements?

No, the library itself doesn’t work like that (marks are associated with content, and can’t be stored for places with no content. That being said, if you just want something like Enter to not clear the marks when you continue typing, storedMarks can indeed help (see the splitBlockKeepMarks command). If you want the marks to stick around even when the cursor is moved somewhere else, you’ll have to implement that with a plugin that keeps track of such marks and resets them when the selection is moved to the empty block.

1 Like

Maybe. Is there an example somewhere of how to actually use storedMarks? That page is a little sparse.

Yea we ran into this as well. We ended up creating a special inline node that we called a “markholder” and when you leave an empty paragraph with stored marks, we insert one of these markholders into the empty paragraph. When the cursor is put back into the empty paragraph, we delete the markholder and set stored marks.

Doing this plugin was not trivial as there are a lot of weird corner cases (undo/redo history, block size changing when font size changes, serializing stored marks when saving content) and the logic ended up being a bit complex. I’m not sure what else Prosemirror could do here but this type of behavior does seem really common for users (since this is how most word processors work I believe).

Another aspect to this that can be a bit confusing is that block nodes can hold marks. Maybe there is some solution where marks are stored on the text block and then somehow synced up with textnodes?