Forbid further marks inside a node

Dear prosemirror community,

working on an emoji autocompletion functionality (triggered by typing <:>), I try to find a way to forbid marks when entering the search query.

At the moment, typing :black_right_ results in _right_ being converted to ‘right’ (with the italic mark).

The code in question can be found here: text/Emoji.js at f08da45e6242860b2aa2c48badbd562f86b73fc9 · nextcloud/text · GitHub

I already tried setting marks: '' in get schema(), but unfortunately, that didn’t help.

From the discusssion in How to exclude Marks from beeing added to a NodeType - #4 by marijn I undestand that there was (is?) no easy way to forbid marks inside a node. You mentioned that filterTransaction could be used to achieve that, but I fail to understand how this could look like. Do you by chance have an example on how to use filterTransaction the way I desire?

Kind regards

It sounds like you want to prevent an input rule that changes underscores to an emphasis mark from triggering, not forbidding marks in general. No such input rule is defined in the core library, so you might want to look into where you’re getting this input rule from.

Hey, I see you are using tiptap v1. In v2 we changed the regular expressions for mark input rules for this exact reason.

v1 regex: /(?:^|[^_])(_([^_]+)_)$/

v2 regex: /(?:^|\s)((?:_)((?:[^_]+))(?:_))$/

With this change, a mark is added only if you are at the beginning of a block or there is a space before it. This also has limitations but works better overall.

Thanks @philippkuehn, that makes a lot of sense. As far as I know, migrating Nextcloud Text to tiptap v2 is planned. For now, adjusting the mark input/paste rules to the v2 ones should do the trick.

Also thanks a lot @marijn for your response. You’re right that changing the input rule is the right approach here - and @philippkuehn even pointed me to where to do this exactly. Please forgive my unprecise question, I’m still pretty new to the prosemirror and tiptap world and don’t have a good overview yet :grimacing:

@mejo Tiptap co-creator here. I hope you don’t mind my question: How did you decide to ask a question on the ProseMirror forum when you’re using Tiptap? You’re not alone, but I try to understand how we can keep the support burden for Marijn low, and I would love to get all Tiptap-related questions in front of us instead. If you don’t mind to give me a short feedback on this, send me an email: Thanks! :v:

1 Like