What is the best way to go about implementing a special node called container
which satisfies the following properties:
- All block-level elements must exist inside a
container
. - Splitting a paragraph
A
inside a containerC
(i.e.C(A)
) yields two new nested containers (i.e.C(C(A1), C(A2))
). container
s may contain either one block element OR two or more nestedcontainer
s.container
s are functionally invisible to the user, e.g. in the previous example, putting the cursor at the start ofA2
and pressing backspace should merge the two paragraphs, yieldingC(A)
(sinceC(C(A))
is considered invalid), even though the paragraphs are structurally isolated in their owncontainer
s. In this case, the outermostcontainer
should be retained.
I began by trying to represent these properties in-schema where a container
is specified to have content (block | (container{2,})
, but this resulted in me being unable to split paragraphs.
The second idea I considered was registering a appendTransaction
listener which would restructure the document on the fly to satisfy the above constraints, but this is proving difficult to implement elegantly. Any suggestions on how I might implement a node with such specific behavior are appreciated.