Markdown Newlines and Ranges


We ran into an issue I would like your opinion on.

We use markdown as our storage format and have implemented an annotation feature with Prosemirror.

Say I have a text with annotations (ranges).

The user enter several newlines (hitting enter or, worse, shift+enter). Our annotations update their positions accordingly (they are stored in a separate object).

On save Prosemirror export to Markdown following CommonMark specs : empty newlines are deleted but our annotations have no chance to update their positions at this step in the process.

Then our “annotations” are “de-synchronized” and cannot be re-applied on next page load of the content.

On this behavior is clear between markdown and WYSIWYM mode, but how can we maintain ranges position in this case ?

Do you have an idea ? Are we doing something wrong here ?


This isn’t something ProseMirror supports – Markdown is considered a lossy export format, and positions that refer to ProseMirror documents don’t really have a clear meaning in the exported Markdown text. You could try to build a solution by writing you own serializer, but the library doesn’t help much on that point.

Thanks for your answer. What would be your advise on this ? Choosing HTML or saving our document in JSON ? (And thus saving along with the document all meta informations)

You’ll have a similar problem with HTML, so JSON is the way to go if you want to preserve the exact document (and thus be able to reuse positions in it).

Ok, thanks for your fast feedback