DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:prosemirror:devel:node_validation

ProseMirror Development

Node validation

We can validate a Node created from JSON against the schema with the Node.check() function1). This function will throw an exception if the Node is invalid. However, we currently don't get much information from the thrown exception2).

Currently, the best approach seems to be to add some console output to the only place where we do have access to the information about which Fragment is causing the problem. It is in prosemirror-model/dist/content.js, in the function matchFragment. Starting at line 288 this could look like the following:

ContentMatch.prototype.matchFragment = function (fragment, from, to) {
    var this$1 = this;
    if ( from === void 0 ) from = 0;
    if ( to === void 0 ) to = fragment.childCount;
 
  if (from == to) { return this }
  var fragPos = from, end = this.expr.elements.length
  for (var ref = this, index = ref.index, count = ref.count; index < end; index++, count = 0) {
    var elt = this$1.expr.elements[index], max = this$1.resolveValue(elt.max)
 
    while (count < max && fragPos < to) {
      if (elt.matches(fragment.child(fragPos), this$1.attrs, this$1.expr)) {
        count++
        if (++fragPos == to) { return this$1.move(index, count) }
      } else {
        console.error('Fragment not allowed in ' + this$1.expr.nodeType.name);
        console.error(fragment.child(fragPos));
        break
      }
    }
    if (count < this$1.resolveValue(elt.min)) { return null }
  }
  return false
};
plugin/prosemirror/devel/node_validation.txt · Last modified: 2017-06-21 13:15 by grosse

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki