From 970c2aac13fdb4f348657f345e9ab8493316e7db Mon Sep 17 00:00:00 2001 From: Jolene Langlinais Date: Fri, 24 Apr 2020 11:28:21 -0400 Subject: [PATCH] docs(concepts): include normalizing inline default behavior (#3637) Signed-off-by: irmerk --- docs/concepts/02-nodes.md | 2 +- docs/concepts/10-normalizing.md | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/concepts/02-nodes.md b/docs/concepts/02-nodes.md index 5828c6390..a43f36ab9 100644 --- a/docs/concepts/02-nodes.md +++ b/docs/concepts/02-nodes.md @@ -105,7 +105,7 @@ But in certain cases, like for links, you might want to make them "inline" flowi > 🤖 This is a concept borrowed from the DOM's behavior, see [Block Elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Block-level_elements) and [Inline Elements](https://developer.mozilla.org/en-US/docs/Web/HTML/Inline_elements). -You can define which nodes are treated as inline nodes by overriding the `editor.isInline` function. (By default it always returns `false`.) +You can define which nodes are treated as inline nodes by overriding the `editor.isInline` function. (By default it always returns `false`.) Note that inline nodes cannot be the first or last child of a parent block, nor can it be next to another inline node in the children array. Slate will automatically space these with `{ text: '' }` children by default with [`normalizeNode`](https://docs.slatejs.org/concepts/10-normalizing#built-in-constraints). Elements can either contain block elements as children. Or they can contain inline elements intermingled with text nodes as children. But elements **cannot** contain some children that are blocks and some that are inlines. diff --git a/docs/concepts/10-normalizing.md b/docs/concepts/10-normalizing.md index 65c24b32b..de9bfda7a 100644 --- a/docs/concepts/10-normalizing.md +++ b/docs/concepts/10-normalizing.md @@ -14,7 +14,9 @@ Slate editors come with a few built-in constraints out of the box. These constra 3. **Block nodes can only contain other blocks, or inline and text nodes.** For example, a `paragraph` block cannot have another `paragraph` block element _and_ a `link` inline element as children at the same time. The type of children allowed is determined by the first child, and any other non-conforming children are removed. This ensures that common richtext behaviors like "splitting a block in two" function consistently. -4. **The top-level editor node can only contain block nodes.** If any of the top-level children are inline or text nodes they will be removed. This ensures that there are always block nodes in the editor so that behaviors like "splitting a block in two" work as expected. +4. **Inline nodes cannot be the first or last child of a parent block, nor can it be next to another inline node in the children array.** If this is the case, an empty text node will be added to correct this to be in complience with the constraint. + +5. **The top-level editor node can only contain block nodes.** If any of the top-level children are inline or text nodes they will be removed. This ensures that there are always block nodes in the editor so that behaviors like "splitting a block in two" work as expected. These default constraints are all mandated because they make working with Slate documents _much_ more predictable.