Hi, I would like to support both of the following use cases:
Copy+pasting from a Word document will preserve any formatting applied from the Word document e.g. bold, font size, bullet points, etc
Copy+pasting some HTML blurb will apply formatting e.g. hello <b>world</b> will paste as “hello world”
On top of that, we would like to add custom sanitization on paste.
I have tried using handlePaste which handles the second use case well but not the first. I also tried transformPasted which handles the first use case but not the second.
Apologies if I’m missing something obvious but is there a way to support both? Thanks
Insofar as you define parse rules for your nodes and marks that match the HTML you’re pasting, the behavior you describe should be happening by default. For example, the default strong mark in prosemirror-schema-basic will match <b> tags.
Apologies but it doesn’t seem to work by default? I tried pasting some HTML blurb on the live demo on your website and it doesn’t automatically format it.
What do you copy? If you copy the HTML as a text it won’t work, you’ll have write some code to convert HTML text to a ProseMirror Slice ( for ex. by creating a div, setting its innerHTML and using DOMParser to create the Slice ).
If you copy html content from a website for ex with ctrl-c - ctrl-v it will work in the example editor too.