Nested Mark Exclusion

Hey there,

is it possible to define a mark in such a way that it can be nested within other marks but not vice versa? Or is this not possible due to the way marks work?

Here’s an example where <em> can be contained within <strong> but not the other way round.

As far as I can tell, excludes: "_" would block both cases from occurring.

This should be allowed:

<strong><em>em can be within strong</em></strong>

This should not be allowed:

<em><strong>strong</strong> can’t be within em</em>

Marks don’t really contain each other — each node may have a set of marks that apply to it, and those are ordered (by the order in which they occur in the schema), but your question sounds like you’re expecting other kinds of nesting to apply.

Well, what I’m trying to do is to have a mark that can either be fully overlapped by another mark or not at all - but not partially.

ProseMirror’s built-in mark management won’t help you with that—it doesn’t track marks as continuous sequences, but rather as metadata on nodes that happen to be adjacent. You might be able to do what you want with an appendTransaction plugin property which checks the invariant on the new document and fixes things up when necessary.

1 Like

Thank you very much for that hint :slight_smile: