Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds support for pasting links and images in the refactored ZUIEditor. I've also done some research into how copy/paste works.
Pasting in Remirror/ProseMirror is handled almost automatically, using the
parseDOM()
hook in theMarkExtensionSpec
. When copy/pasting, the browser will paste the HTML, and ProseMirror will parse it using the matching extension. If there is no matching extension, the HTML will be stripped. For example, pasting bold text whenBoldExtension
is enabled inserts text marked with theBoldExtension
mark, but if we disable the extension, the text is pasted with the bold styling stripped, as a regular paragraph. Perfect!Our custom extensions
LinkExtension
andImageExtension
did not properly implementparseDOM()
, because we did not actually parse any attributes. All this PR does in order to make pasting work is to parse and transfer the correct attributes from the pasted DOM.Pasting is already supported by the builtin extensions we use, i.e.
HeaderExtension
andBoldExtension
. I have tried them and they work as expected. As we add more extensions, builtin or custom, we need to make sure pasting works as it should.I have also researched the more advanced
createPasteRules()
hook which allows an extension to create more arbitrary paste rules, which might become necessary if we build extensions with a more arbitrary DOM representation. Here's a rough cut from that experimentation.Screenshots
None
Changes
LinkExtension
ImageExtension
Notes to reviewer
None
Related issues
Undocumented