Copying in a prosemirror friendly format

Hi,

I have defined a complex node type to represent references to data structures. Dragging and dropping a selection that contains this Node within the editor works well, despite the node not having a correct parseDOM function. Somehow, drag and drop from within the editor do not trigger parseDOM, I suspect it simply move nodes around so it avoids reparsing the HTML content => it works even for nodes without a correct parseDOM. This might be related to the data-pm here? image

But when pasting content, parseDOM is triggered. That’s problematic because this component is very complex and thus slightly annoying to parse, it’s not the ideal solution to me. I’d like to avoid parsing altogether, as it’s already the case for dragging and ropping.

First question: how can I get the same behaviour when drag and dropping and when copy-pasting, when the copy or the drag comes from the editor itself (so the event clipboardData can be controlled)?

If that’s not possible, my second idea is to tweak the copy-paste system as follow:

  1. instead of having only text/plain and text/html, I also want to add something like application/prosemirror when copying content from prosemirror

  2. I’d like the application/prosemirror format to be, well, prosemirror friendly, in the sense that it should be easy to generate when copying some content, and easy to parse when pasting some content

  3. when pasting, detect this application/prosemirror format in priority and use it

  4. and 3) shouldn’t be too hard, there are a few methods to do so But for 2), is there already an appropriate format that can easily be encoded/decoded by prosemirror? A bit like when we display slices in prosemirror text format, can we parse this string back to generate a node?

1 Like