How should be a definition for a line break node rendering <br> element look like?
What I desire is similar behaviour to slate-soft-break but it would insert '<br>' instead of '\n'.
Should it be an Inline node with isVoid:true? But all Block and Inline nodes contains by default a Text node. So how to prevevent directional keys from "entering" this node and just "skip" it.
So basically the question is how to create an empty, non-focusable node.
Since the reason for all this was to add soft break on shift+enter and to make Slate output a HTML markup with <br/> elements instead of \n, there was no reason to serialize and deserialize <br/> elements into some kind of node. It is sufficient to deserialize the HTML <br/> element into a Text node with content set to \n and afterwards serialize those Text nodes back into <br/> element.
With this solution, we can caontinue using the slate-soft-break plugin and just add following rules into our schema:
// Rule handling line breaks
{
deserialize(el) {
if (el.tagName !== 'br') return;
return {
kind: 'text',
text: '\n',
};
},
serialize(object, children) {
if (object.type !== 'text') return;
if (children !== '\n') return;
return (
<br/>
);
},
},
Most helpful comment
Since the reason for all this was to add soft break on
shift+enterand to make Slate output a HTML markup with<br/>elements instead of\n, there was no reason to serialize and deserialize<br/>elements into some kind of node. It is sufficient to deserialize the HTML<br/>element into a Text node with content set to\nand afterwards serialize those Text nodes back into<br/>element.With this solution, we can caontinue using the slate-soft-break plugin and just add following rules into our schema: