Insert newlines when unrecognised block element breaks up an inline formatting context
Description
Reported by @jkcs: https://github.com/udecode/plate/pull/2729#issuecomment-1801219812
When deserializing HTML and an unrecognised HTML block element breaks up an inline formatting context, newlines should be inserted to ensure that the contents of the block element appear on separate lines to the inline formatting contexts either side of it.
Steps to Reproduce
<div>One<div>two</div>three</div>
- Open the above HTML string in a browser and copy all
- Go to https://platejs.org
- Clear all text in the playground
- Paste
- See the incorrect result: "Onetwothree"
Expected Behavior
The resulting text node should contain "One\ntwo\nthree" to match the standard browser behaviour.
Note that the newline preceeding the block should only be added if the block is preceeded by a non-empty inline formatting context. Likewise, the newline following the block should only be added if the block is followed by a non-empty inline formatting context.
If the HTML block element has been successfully parsed to a Slate node, no newlines need be added.
Bounty
Click here to add a bounty via Algora.
Funding
- You can sponsor this specific effort via a Polar.sh pledge below
- We receive the pledge once the issue is completed & verified
Another case that should be handled: <div>one</div><div>two</div> should output "one\ntwo".
Also, asymmetrical cases: <div>one</div>two and one<div>two</div>.