I’m trying to figure out how to enforce a document structure across different nodes of a document. In the image, the question has parts (a) and (b) and each part can have subparts (i), (ii), (iii), etc… The structure of these parts and subparts are duplicated in the Markscheme section of the document. There are also other things that need to be synced as noted by the highlighting in the picture, but I think once I figure this out I can figure those out, too.
What I would like to do is allow a user to create a question adding parts and subparts to the question section and have those changes duplicated in the markscheme section. They would then be able to add content to the markscheme section, but they would not be able to add/remove parts and subparts from it.
What would be the recommended way to add/remove nodes from the markscheme?
What I am currently attempting is when I insert the node in the question, I determine a partIndex (0th part, 1st part, 2nd part…) and subpartIndex, then I find the part/subpart node directly before that in the markscheme. However, this gives me the node and not a document position. I know it’s not recommended to try to determine a position via a node so I’m kinda stuck. According to this I should be mapping through transactions but I’m not sure what that would look like. Do I need to track the positions with EVERY change to the document? Maybe I’m just not understanding how mapping works.
Finally, where would be the best place to insert/remove nodes from the Markscheme. Should I do it in the command that creates them in the question section or should I create a plugin that uses appendTransaction to detect the modification of the question section and append a transaction that modifies the markscheme section in the same way?
Thanks a lot!