Replace on paste (or any other string/char) #1225
-
I'm using latest tiptap 2 beta and wondered if it is possible to replace some characters which are pasted into the editor, in my case replace all I looked into paste rules in other extensions and tried to create a new extension, but I'm at a dead end here: import { Extension, markPasteRule } from '@tiptap/core'
const nbspReplacer = Extension.create({
addPasteRules() {
return [
markPasteRule(/\u00A0/, this.type)
]
}
}) I don't see a way to specify how to replace it, e.g. I don't want to create a new node or something but only replace single chars. https://www.tiptap.dev/examples/savvy does exactly this with input rules (replacing something with emojis) ... import { Extension } from '@tiptap/core'
import { InputRule } from 'prosemirror-inputrules'
export const SmilieReplacer = Extension.create({
name: 'smilieReplacer',
addInputRules() {
return [
new InputRule(/-___- /, '😑 '),
[...]
]
},
}) ... but I need it only for paste rules. Is this possible? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 14 replies
-
Did you succeed? I'm trying the exact same thing, with no success. |
Beta Was this translation helpful? Give feedback.
-
Would this could be done by using the newly introduced |
Beta Was this translation helpful? Give feedback.
-
@doits What about this? const NBSPReplacer = Extension.create({
name: 'npspReplacer',
addPasteRules() {
return [
textPasteRule({ find: / /g, replace: ' ' }),
textPasteRule({ find: /\\u00A0/g, replace: ' ' }),
]
},
}) |
Beta Was this translation helpful? Give feedback.
@doits What about this?