Void nodes can contain blocks?
See original GitHub issueDo you want to request a feature or report a bug?
Either a bug or a question 😃
What’s the current behavior?
The current behavior is that as of https://github.com/ianstormtaylor/slate/pull/1663/files#diff-4a9856aa0d6cae32f324558beae45156, isVoid
blocks can now contain child blocks as opposed to only text nodes. Consider:
/** @jsx h */
import h from '../../helper/hyperscript';
// This test case verifies an image block cannot conatin other block types.
export const input = (
<value>
<document>
<title>Title</title>
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png"><h6>Images - Header</h6></image>
<image src="https://www.notarealimage.png"><blcode>Images - BlockCode</blcode></image>
<image src="https://www.notarealimage.png"><quote>Images - Quote</quote></image>
<image src="https://www.notarealimage.png"><title>Images - Title</title></image>
<image src="https://www.notarealimage.png"><p>Images - Paragraph</p></image>
<image src="https://www.notarealimage.png">
<ol><oli>Images - OrderedListItem</oli></ol>
</image>
<image src="https://www.notarealimage.png">
<ul><uli>Images - OrderedListItem</uli></ul>
</image>
<image src="https://www.notarealimage.png"><b><i><u><c>Images - Marks</c></u></i></b></image>
<image src="https://www.notarealimage.png">
<table><tr><td>Images - Table</td></tr></table>
</image>
<p>Paragraph</p>
</document>
</value>
);
export const output = (
<value>
<document>
<title>Title</title>
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<image src="https://www.notarealimage.png" />
<p>Paragraph</p>
</document>
</value>
);
This test case (perhaps a bit contrived) verified that malformed image blocks with children would have their children removed by the schema rules. Now what happens is that these non-text-node children are allowed to exist.
What’s the expected behavior?
I’m not sure. The documentation says a void block has one text child, and the PR description seems to indicate that the intention is to give the void block the ability to have arbitrary text, but the removal of the validation rule suggests that the intention is to allow void blocks to have arbitrary children. But I can’t help but wonder what the point of the void node is then in that case?
Happy to submit a PR if that’s the direction we need to go. Just wanted to check in and get my mental model straightened out at least 😃
Thanks for your time
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:6 (4 by maintainers)
Top GitHub Comments
I’ve been working on an
isAtomic
schema controlled option for blocks for an issue here: https://github.com/ianstormtaylor/slate/issues/1654But it’s really early and I’m still working on developing the test cases up front. Lots of corner cases.
I think
isVoid
will remain as a node whose content is out of the concern of Slate, and treated as a single, atomic block.We might need to introduce
isAtomic
or similar if people want to have nodes that are atomic but still controlled by Slate. I haven’t really thought that through though.