Detect not compatible content Vs modified content

Hi,

I try to use prosemirror as new editor with legacy HTML content.

I need to test an HTML content to define if the content can be edited with prose mirror or not (fallback to HTML code editor).

Today I test content with this function :

function contentIsCompatible(html) {
  let contentElement = document.createElement('div');
  contentElement.innerHTML = content;

  let editorDocument = DOMParser.fromSchema(schema).parse(contentElement);
  let editorDocumentFragment = DOMSerializer.fromSchema(schema).serializeFragment(editorDocument);

  let editorElement = document.createElement('div');
  editorElement.appendChild(editorDocumentFragment);

  return contentElement.isEqualNode(editorElement);
}

It “works”, but I can’t distinguish the reason of mismatch element.

What I need is to be able to, detect removed node (for example div node not allowed in schema) Vs node modified by prisemirror (for example <i> modified to <em>).

From my point of view, first case (with missing div) is not compatible but the second one (with <i> element) is compatible.

Is there a way, with DOMParser and/or DOMSerializer to achieve this ?

Thank you

No, this is not functionality that the library provides. I think you’ll have to write a custom checker.