mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-18 21:21:21 +02:00
Add rules to prevent empty inline nodes
This commit is contained in:
@@ -47,7 +47,7 @@ const BLOCK_CHILDREN_RULE = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default schema rule to have at least one text node in blocks
|
* A default schema rule to have at least one text node in blocks/inlines
|
||||||
*
|
*
|
||||||
* @type {Object}
|
* @type {Object}
|
||||||
*/
|
*/
|
||||||
@@ -85,6 +85,24 @@ const INLINE_CHILDREN_RULE = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A default schema rule to ensure that inline nodes are not empty
|
||||||
|
*
|
||||||
|
* @type {Object}
|
||||||
|
*/
|
||||||
|
|
||||||
|
const INLINE_NO_EMPTY = {
|
||||||
|
match: (object) => {
|
||||||
|
return object.kind == 'inline'
|
||||||
|
},
|
||||||
|
validate: (inline) => {
|
||||||
|
return inline.text == ''
|
||||||
|
},
|
||||||
|
normalize: (transform, node) => {
|
||||||
|
return transform.removeNodeByKey(node.key)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A default schema rule to ensure that void nodes contain a single space of content.
|
* A default schema rule to ensure that void nodes contain a single space of content.
|
||||||
*
|
*
|
||||||
@@ -194,6 +212,7 @@ const schema = Schema.create({
|
|||||||
DOCUMENT_CHILDREN_RULE,
|
DOCUMENT_CHILDREN_RULE,
|
||||||
BLOCK_CHILDREN_RULE,
|
BLOCK_CHILDREN_RULE,
|
||||||
MIN_TEXT_RULE,
|
MIN_TEXT_RULE,
|
||||||
|
INLINE_NO_EMPTY,
|
||||||
INLINE_CHILDREN_RULE,
|
INLINE_CHILDREN_RULE,
|
||||||
INLINE_VOID_TEXT_RULE,
|
INLINE_VOID_TEXT_RULE,
|
||||||
INLINE_VOID_TEXTS_AROUND_RULE,
|
INLINE_VOID_TEXTS_AROUND_RULE,
|
||||||
|
Reference in New Issue
Block a user