Hi,
I have set up a nodeView for wrapping tags inside a wrapping container in which I append another for displaying a resize handler in the corner above the image, another as a tooltip displaying the width of the image.
The DOM structure of the nodeView is:
At present, when I save the content to my database, the DOM generated by the nodeView is saved in my database. Then, when I reload the content from my database into my editor, Prosemirror strangely unwrap the innerText of the tooltip span and “relocates” it above the wrap span.
I get the structure below:
The same happens if the wrap span contains text content (<span class="wrap">hello<span class="resize">...</span>). It gives after reloading from database: <div class="ProseMirror">hello200px<span...</span></div>.
Should I remove the generated DOM from the content before saving to database ? Or is this rather related to the Schema not parsing the spans correctly ?
It sounds like you’re using the editor’s innerHTML and saving that in the database. In general, that’s a bad idea. Define data-only toDOM methods for your node types, and use a DOMSerializer to create a clean representation of the document when saving.
HI @marijn,
I use document.createElement and innerText inside the constructor of my NodeView class, then assign the built element to the dom property of the class. Is it a wrong way ?
Here’s my code:
I don’t understand: I save to my database the HTML produced by Prosemirror in the editor using view.dom.innerHTML, which is valid HTML. And I load it from my database into the editor using DOMParser.
Do I really need to use a DOMSerializer to get the content from the editor ?
I cannot find an example in the docs and not sure about how to use it.