Unknown Node Types

I have a case where the input dom is not always known. So the schema will not have a node type defined for every possible element coming in from the dom. But I do not want to lose or modify the original unknown dom elements. I would like to just display these unknown dom elements as non-editable nodes in the editor. Is there a way to do this? Some kind of catch all for nodes not defined in the schema?

I would also need to be able to serialize these unknown elements back into the source format with no changes made to them.

1 Like

Interesting use case. It may be possible to setup a node that acts as a catchall.

Something like:

{
  tag: "*", // css selector to match everything
  priority: 0, // make it have the lowest priority
}

You’ll also need to setup toDOM and fromDOM handlers. These will somehow need to act like pass throughs. Look at http://prosemirror.net/ref.html#model for help on setting up a custom node type in your schema.

Overall, I think it is possible but will take some fiddling learning to figure out how it should work.

This method totally worked. Thanks a bunch for pointing me in the right direction @wes-r. Beyond setting up the parseDOM and toDOM methods for the nodes I also made a nodeview to display them differently and keep them un-editable.

1 Like

@jordandh This is probably a real long shot, but I have the same use case, and was wondering if you could share the solution you came up with?

3 Likes