How to combine schemas? (markdown + tables)

So I’ve been using prosemirror with the prosemirror-markdown schema and the example setup for a while and it’s been working the way I’ve been wanting it to so far. I’d like to add tables to the editor so I downloaded the prosemirror-tables package.

The demo.js script for prosemirror-tables shows combining the basic schema with the tableNodes like this:

let schema = new Schema({
  nodes: markdownSchema.spec.nodes.append(tableNodes({
    tableGroup: "block",
    cellContent: "block+",
    cellAttributes: {
      background: {
        default: null,
        getFromDOM(dom) { return dom.style.backgroundColor || null },
        setDOMAttr(value, attrs) { if (value) attrs.style = (attrs.style || "") + `background-color: ${value};` }
      }
    }
  })),
  marks: markdownSchema.spec.marks
})

And again I’m combining it with the prosemirror-markdown schema in my program

but what happens when I try combining these schemas it completely “breaks” the schema. Whenever I press any key in the editor it just deletes the entire word behind the cursor, and will keep doing so as you type until the entire document has been erased.

It also causes the menu bar items like “Type > Code” and everything else that has an enable function to show disabled and not work, and eliminates and input rules.

I’ve tried multiple other ways of combining the schemas, such as requiring the markdownSchema as a var instead of a const, straight up appending the tableNodes to the markdownSchema instead of constructing a new one, like this:

markdownSchema.spec.nodes.append(tableNodes({
    tableGroup: "block",
    cellContent: "block+",
    cellAttributes: {
      background: {
        default: null,
        getFromDOM(dom) { return dom.style.backgroundColor || null },
        setDOMAttr(value, attrs) { if (value) attrs.style = (attrs.style || "") + `background-color: ${value};` }
      }
    }
  }))

But this doesn’t actually add any nodes to the schema, which I kind of get.

So the method shown in the demo.js does actually add the tableNodes to the markdown schema, but then when you go into the ProseMirror editor it just deletes words when you type and breaks everything.

Any help appreciated, especially if anyone has experience with using tables and markdown together in prosemirror

I ended up just using the basic schema and serializing the document to JSON instead of markdown and got tables working perfectly.