Hi,
It seems like PM insists on having a single text node as the content of a paragraph (probably unless there are different marks). For example, the following:
let twonodes = [pm.schema.nodes['text'].create({}, "bit 1", []),
pm.schema.nodes['text'].create({}, "bit 2", [])]
let p = pm.schema.nodes['paragraph'].create({}, twonodes, [])
pm.tr.insert(1, p).apply()
The result is:
{"type":"paragraph","attrs":{},"content":[{"type":"text","attrs":{},"text":"bit 1bit 2"}]}"
Is there a way to enforce a desired structure without having PM decide what the tree looks like? Even when I create the text nodes with different attributes (I have modified the schema to allow some extra attributes in paragraph and text nodes), it still collapses them and just keeps the attributes from only one of the nodes. I would expect it not to automatically concatenate/merge nodes when they have different attributes and/or marks.
Incidentally, I have this general problem with PM unpredictably deciding to restructure the model during transformations. It appears unpredictable because the rules are not documented, they are just heuristics expressed in code that is not always trivial to follow. It would help if the rules were spelled out somewhere. I understand that most people might not care about the details and just expect PM to do the sensible thing. But I care because I have a separate document model that I need to keep in sync with PM’s model.
Thanks much for your help! Boris
PS I’m not using the latest PM version (I’ve been holding off porting until APIs and behavior stabilize). I’m using 0.9.1. Let me know if there are recent changes that affect the above behavior and might fix my problem?