ckeditor / ckeditor5

Powerful rich text editor framework with a modular architecture, modern integrations, and features like collaborative editing.
https://ckeditor.com/ckeditor-5
Other
9.45k stars 3.7k forks source link

[GHS] `div` elements wrapped in `h` or `p` lead to data loss or changed markup #14249

Open Witoso opened 1 year ago

Witoso commented 1 year ago

Drupal issue: https://www.drupal.org/project/drupal/issues/3362002 Rel: #13803

  1. Add the following snippet via source (https://ckeditor.com/ckeditor-5/demo/html-support/):
    <h2>
    <div>Test</div>
    </h2>
  2. Turn off the source view.
  3. Return to the source view.

✔️ Expected result

The html stays the same.

❌ Actual result

The html changes to the following, stripping the h2

<div>
    Test
</div>

A bit different behavior for for p

<p>
    &nbsp;
</p>
<div>
    Test
</div>
<p>
    &nbsp;
</p>

If you'd like to see this fixed sooner, add a 👍 reaction to this post.

dtdesign commented 1 year ago

It is worth nothing that the editor behavior is technically correct, because the HTML spec only permits “phrasing content” inside the h1-h6 elements [1]. “Phrasing content” is a subset of “flow content” which div belongs to [2].

[1] https://html.spec.whatwg.org/multipage/sections.html#the-h1,-h2,-h3,-h4,-h5,-and-h6-elements [2] https://html.spec.whatwg.org/multipage/dom.html#flow-content