plate icon indicating copy to clipboard operation
plate copied to clipboard

Insert newlines when unrecognised block element breaks up an inline formatting context

Open 12joan opened this issue 2 years ago • 1 comments

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>
  1. Open the above HTML string in a browser and copy all
  2. Go to https://platejs.org
  3. Clear all text in the playground
  4. Paste
  5. 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
Fund with Polar

12joan avatar Nov 08 '23 10:11 12joan

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>.

12joan avatar Nov 20 '23 09:11 12joan