PasteRule does not work for nodes
See original GitHub issueDescribe the bug
When attempting to add a pasteRule
for a Node
, it does not work as the pasteRule
helper function have a call to a Mark
node (note how we call addToSet
on the created node, which may not be a mark but a node):
nodes.push(child.cut(start, end).mark(type.create(attrs).addToSet(child.marks)));
Steps to Reproduce / Codesandbox Example
- Add a paste rule to any node such as a media embed
pasteRules({type}) {
return [pasteRule(/SOME_YOUTUBE_REGEX/g, type, (url) => ({src: url}))]
}
- try to paste a heading:
https://www.youtube.com/watch?v=H08tGjXNHO4
- See error in console:
Uncaught TypeError: type.create(...).addToSet is not a function
Expected behavior
a new MediaEmbed node should be created with the given attrs
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:22 (19 by maintainers)
Top Results From Across the Web
prosemirror-paste-rules | Remirror
A function that transforms the match into the content to use when creating a node. Pass () => {} to remove the matched...
Read more >Custom extensions – Tiptap Editor
Let's walk through a few common use cases. The default Blockquote extension can wrap other nodes, like headings. If you want to allow...
Read more >prosemirror-paste-rules - npm
The problem. You want to automatically transform pasted content within your editor into nodes marks, or different text.
Read more >How to use the tiptap-commands.nodeInputRule function in ...
Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues...
Read more >Tiptap editor, how to paste multiple empty lines?
I'm trying to extend the Paragraph extension to add a <p></p> for each new lines, but I can't make the regex to work....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m also facing issue w/ implementing a nodePasteRule and wondered if anyone has gotten something similar to @kfirba solution working w/ TipTap 2 and the addPasteRules method? So far I’ve tried altering the code shown to accept a config object rather than just arguments to be closer to the TipTap nodeInputRule & markPasteRule, but I’m getting
Uncaught TypeError: find is not a function
. Thanks for making TipTap and any further suggestions.@philippkuehn I’ve created a simple helper function to solve that:
Basically it is a very similar function as
markPasteRule
but it just creates the node with the given attribute instead of trying to add a mark ~and does not contain awhile
loop. Even in themarkPasteRule
I’m not sure why there is awhile
loop whenmatch
is only every assigned once?~ It seems like thewhile
loop is for theregexp.exec
call due to it attempting to match from thelastIndex
: https://stackoverflow.com/questions/1520800/why-does-a-regexp-with-global-flag-give-wrong-resultsI guess that if you want you could extract the common logic between those 2 methods and just pass a handler to create the node/mark.
What do you think?