From 8402df138e3b145a94ebe4d4fb3d8ccd86c1cf94 Mon Sep 17 00:00:00 2001 From: Samy Pesse Date: Wed, 19 Oct 2016 13:45:14 +0200 Subject: [PATCH] Add rules to prevent empty inline nodes --- src/plugins/schema.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/plugins/schema.js b/src/plugins/schema.js index c0a138011..094839833 100644 --- a/src/plugins/schema.js +++ b/src/plugins/schema.js @@ -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} */ @@ -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. * @@ -194,6 +212,7 @@ const schema = Schema.create({ DOCUMENT_CHILDREN_RULE, BLOCK_CHILDREN_RULE, MIN_TEXT_RULE, + INLINE_NO_EMPTY, INLINE_CHILDREN_RULE, INLINE_VOID_TEXT_RULE, INLINE_VOID_TEXTS_AROUND_RULE,