1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-23 15:32:59 +02:00

update docs

This commit is contained in:
Ian Storm Taylor
2017-10-18 08:58:23 -07:00
parent 63855ed15c
commit c442e52ca6

View File

@@ -124,16 +124,20 @@ The third place you may perform change operations — for more complex use cases
```js ```js
{ {
match: (object) => object.kind === 'block' && object.type === 'quote', match(obj) {
validate: (node) => { return obj.kind == 'block' && obj.type == 'quote',
const invalidChildren = node.filterDescendants(child => child.kind === 'block');
return invalidChildren.size ? invalidChildren : null;
}, },
normalize (change, node, invalidChildren) { validate(quote) {
invalidChildren.forEach(child => { const invalidChildren = quote.nodes.filter(n => n.kind != 'block')
change.removeNodeByKey(child.key); if (!invalidChildren.size) return
}); return invalidChildren
}, },
normalize(change, quote, invalidChildren) {
invalidChildren.forEach((node) => {
change.removeNodeByKey(node.key)
})
},
}
``` ```
When a rule's validation fails, Slate passes a [`Change`](../reference/slate/change.md) object to the `normalize()` method on the rule. You can use this object to apply the changes necessary to make your document valid on the next normalization pass. When a rule's validation fails, Slate passes a [`Change`](../reference/slate/change.md) object to the `normalize()` method on the rule. You can use this object to apply the changes necessary to make your document valid on the next normalization pass.