Is there a way to reset all or some node attribute when the node is split?
My issue concerns paragraphs with id attribute (use for internal links). When the cursor is not at the end of a paragraph & user hit ENTER, the paragraph is split but both (new & old) paragraph keep the original id attribute …
Any way to prevent this behavior? (it does not happen when cursor is at the end).
You could write your own command to handle enter, which reassigns an id to the split-off part of the node, but there’s many things in ProseMirror that can cause nodes to be copied or split (copy/paste, drag/drop, various commands that change document structure), so maintaining unique ids is usually done with an appendTransaction hook that checks for duplicated or missing ids, and reassigns them.
The thing to remember here is that when you have things attached to (or referencing) a node’s ID, if the duplicated node ends up BEFORE the original paragraph, the code shown will assign the original node to have the new ID since it is encountered after the duplicate (which is earlier in the document). For split paragraphs it will work fine as the new node with the duplicated ID will come after the original.
In my implementation, I added romgere’s code in my main appendTransaction function for my main plugin and I also added code to the transformPasted in my paste plugin to set new IDs prior to nodes being pasted in, but for split paragraphs, the code presented will work. Just keep in mind all situations that can cause the duplicated node ID to get inserted prior to the original node, which would change the ID for the node you want to keep its ID. In that case, anything that referenced the original node will now reference the inseted node.