contentDOM when returning a dom node from toDOM()

Hey, when writing the schema spec, one has to decide between either returning a dom node or a DOMOutputSpec. When returning a DOMOutputSpec, one can specify the place where children of the node will be placed (the “contentDOM”) with a 0.

I am in a situation where I already have a dom node that should become part of what is returned with toDOM, but I also need to place children inside of the node:

<table>
  <caption>The <i>caption</i></caption> <!-- The <caption>-node is preexisting -->
  <tbody><!-- Children go here --></tbody>
</table>

I wonder if there is a way to specify the contentDOM (0) when returning a dom node like this? If I were to return a DOMOutputSpec instead, I would have to translate the preexisting <caption>-node into a DOMOutputSpec somehow.

What do you mean by pre-existing caption node?

If I were to return a DOMOutputSpec instead, I would have to translate the preexisting -node into a DOMOutputSpec somehow.

One way might be to make a wrapper table node which has as its contents “caption tbody”.

The contents of this node are created through another third party library so that I don’t have direct control over what elements are used, etc…

That could be a work-around. But I was wondering of it’s not possible to specify the contentDOM directly (or for that to be added in the next release). That would save me from having to write my own table plugin and I wouldn’t have to convert all existing content to this new structure.

This is easy to support, and I don’t see a reason not to. prosemirror-model 1.12.0 allows this.

3 Likes

Oh wow! Thank you so much.

Nice. Marijn: this is one of the many things I appreciate about how you run this project.

1 Like

So, how to specify where to place a “hole” when we return a dom node from toDOM method? Is that info placed in reference somewhere?

Return a {dom: HTMLElement, contentDOM: HTMLelement} object.

1 Like