1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-26 16:44:22 +02:00

Merge branch 'schema-normalize-transforms' of https://github.com/GitbookIO/slate into schema-normalize-transforms

This commit is contained in:
Samy Pessé
2016-10-24 18:32:31 +02:00

View File

@@ -96,13 +96,23 @@ const INLINE_CHILDREN_RULE = {
const INLINE_NO_EMPTY = { const INLINE_NO_EMPTY = {
match: (object) => { match: (object) => {
return object.kind == 'inline' return object.kind == 'block'
}, },
validate: (inline) => { validate: (block) => {
return inline.text == '' return block.nodes.some((child) => {
return child.kind == 'inline' && child.text == ''
})
}, },
normalize: (transform, node) => { normalize: (transform, block) => {
return transform.removeNodeByKey(node.key) return block.nodes.reduce((tr, child, index) => {
if (child.kind == 'inline' && child.text == '') {
return transform
.removeNodeByKey(child.key, { normalize: false })
.insertNodeByKey(block.key, index, Text.createFromString(''), { normalize: false })
} else {
return tr
}
}, transform)
} }
} }