In ProseMirror each node and mark can have certain attributes. These attribute are stored on the dom and can be retrieved from the dom via the created
MarkSpec or the
Attributes can also set default values.
One constraint that ProseMirror sets is that attributes must be declared ahead of time. There is no runtime ability to add undeclared attributes dynamically. This can be an issue when consuming a library like
Remirror. Perhaps you want the
paragraph functionality, but also want to add an extra attribute as well. This is where extra attributes come into play.
The following is a work in progress. Please edit the page and provide your suggestions if you notice any problems.
Every extension can be given extra attributes when created.
The above has given a dynamic attribute
id, which assigns a unique
id to every paragraph node as well as giving instruction on how to retrieve that node from the dom and pass the node back to the DOM.
The above could have also been defined like this.
This example accomplishes the same things as the previous example and remirror is smart enough to automatically parse the dom and write to the dom the required values.
Render as data attributes
You can return an array of a key value pair, to determine how your extra attribute is rendered in the DOM.
Extra attributes can also be added via the
RemirrorManager. This can set attributes for a collection of nodes, marks and tags. This is very useful when adding attributes to multiple places in one sweep.