About context and priority

Use case: i have two kinds of paragraphs: p that can contain anchors, and p_nolink that can’t, and which can only be found in a blocklink, like this:

<a><p>no links</p></a>

p_nolink has obviously a parseRule with context: 'blocklink//'.

However, i still need to declare p_nolink before p or else it’s p that will greedily be parsed first.

It works, but it’s easy to miss in more complicated setups. It would be good that prosemirror either:

  • try to parse all nodes and decide which one has the more narrow context
  • or add the possibility to negate a context as in !blocklink//

Trying to automatically rank parse rules by specificity seems too magical (and probably still doesn’t solve the problem, as you might still have ordering issues between rules with the same specificity). Have you seen the priority option to parse rules?

Yes, i did not mean it wasn’t solvable, and indeed priority is the way to go. However in an environment with lots of node types i found it easy to get confused.

So i’m really asking for considering adding a “not” feature for context. Is it something coherent with how context is checked ?

I’m not convinced that helps a lot—you still have to explicitly take the interaction between the parse rules into account to know that you have to add such a negative context, at which point you might as well give them an explicit priority.

I think that in situations like this, where you build something from many building blocks that may interact, the need to audit the relations between the building blocks is something that’s hard to get around.