How to add prosemirror-schema-table into the existing schema?

Sorry, I have another question. I saw the tutorial about adding List schema to existing schema:

var custom_schema = new Schema({
  nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
  marks: schema.spec.marks
})

works great. However, there is no example at all given about how to add the table schema. I have looked all over github and on Google, seems like the instruction is quite limited. I have attempted:

var custom_schema = new Schema({
  nodes: addListNodes(addTableNodes(schema.spec.nodes, 'block+', 'block'), 'paragraph block*', 'block'),
  marks: schema.spec.marks
})

But the following error shows up:

server_9 % node main.js
/Applications/MAMP/htdocs/prosemirror_server/server_9/node_modules/prosemirror-model/dist/index.js:1625
TokenStream.prototype.err = function err (str) { throw new SyntaxError(str + " (in content expression '" + this.string + "')") };
                                                 ^

SyntaxError: Unexpected token '[' (in content expression 'table_row[columns=.columns]+')

I think the culprit is this line:

Thank you in advanced.

I found this thread:

Seems like the following works:

var custom_schema = new Schema({
  nodes: addListNodes(schema.spec.nodes, 'paragraph block*', 'block'),
  marks: schema.spec.marks
})

var custom_schema = new Schema({
  nodes: custom_schema.spec.nodes.append(tableNodes({
    tableGroup: "block",
    cellContent: "block+",
  })),
  marks: schema.spec.marks
})

I am able to get it working to add the steps to the doc.


doc_json = readFileSync('data/doc.txt', () => { null })
doc_json = JSON.parse(doc_json)

// read the initial document (or have it somewhere)
// var doc_node = Node.fromJSON(custom_schema, doc_json);
var doc_node = custom_schema.nodeFromJSON(doc_json)

step_jsons = readFileSync('data/step.txt', () => { null })
step_jsons = step_jsons.toString().split('\n').filter(Boolean)

for (var step_json of step_jsons) {
  step_json = JSON.parse(step_json)
  for (var step of step_json['steps']) {
    var step = Step.fromJSON(custom_schema, step)
    var result = step.apply(doc_node)
    if (result.failed) {

    } else {
      doc_node = result.doc
      // console.log(doc_node.toJSON())
    }
  }
}

console.log(doc_node)

but it seems like there are some unexpected mark_type: RangeError: There is no mark type mark-font-test in this schema This is the step.txt

{"version":300,"steps":[{"stepType":"replace","from":265,"to":265,"slice":{"content":[{"type":"paragraph","attrs":{"align":null,"color":null,"id":null,"indent":null,"lineSpacing":null,"paddingBottom":null,"paddingTop":null,"objectId":null}},{"type":"paragraph","attrs":{"align":null,"color":null,"id":null,"indent":null,"lineSpacing":null,"paddingBottom":null,"paddingTop":null,"objectId":null}}],"openStart":1,"openEnd":1},"structure":true}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":301,"steps":[{"stepType":"replace","from":267,"to":267,"slice":{"content":[{"type":"paragraph","attrs":{"align":null,"color":null,"id":null,"indent":null,"lineSpacing":null,"paddingBottom":null,"paddingTop":null,"objectId":null}},{"type":"paragraph","attrs":{"align":null,"color":null,"id":null,"indent":null,"lineSpacing":null,"paddingBottom":null,"paddingTop":null,"objectId":null}}],"openStart":1,"openEnd":1},"structure":true}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":302,"steps":[{"stepType":"addMark","mark":{"type":"mark-font-test","attrs":{"name":"Acme"}},"from":147,"to":156}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":303,"steps":[{"stepType":"addMark","mark":{"type":"mark-font-size","attrs":{"pt":30}},"from":18,"to":27}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":304,"steps":[{"stepType":"addMark","mark":{"type":"strike"},"from":13,"to":16}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":305,"steps":[{"stepType":"replace","from":11,"to":11,"slice":{"content":[{"type":"text","marks":[{"type":"super"}],"text":"a"}]}}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}
{"version":306,"steps":[{"stepType":"replace","from":12,"to":12,"slice":{"content":[{"type":"text","marks":[{"type":"super"}],"text":"w"}]}}],"clientID":"827fec50-fca0-11ea-9678-71616149d424"}

I looked all over the library, but seems like I cannot find anything called: mark-font-test. Could anyone point me in the right direction? :pray:

Thank you!

That sounds like you’re using the deprecated prosemirror-schema-table module. Don’t—the readme warns you to use prosemirror-tables instead.

1 Like