Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DualContentModelElementSupport doesn't support inline element upcasting into block element #11513

Closed
lauriii opened this issue Mar 24, 2022 · 3 comments · Fixed by #11686
Closed
Assignees
Labels
package:html-support squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.

Comments

@lauriii
Copy link
Contributor

lauriii commented Mar 24, 2022

📝 Provide detailed reproduction steps (if any)

The html-support/integrations/dualcontent~DualContentModelElementSupport is not handling cases where a child node that is an inline element in view changes into a block element in model. Example case where this is happening (in Drupal) is when <a> is wrapping a <drupal-media> element.

Following data:

<a href="example.com">
  <drupal-media></drupal-media>
</a>

Upcasts into (because the links plugin doesn't support linking block elements):

<drupalMedia linkHref="example.com"></drupalMedia>

So imagine the following use case:

<div>
  <a href="example.com">
      <drupal-media></drupal-media>
  </a>
</div>

✔️ Expected result

<htmlDiv>
  <drupalMedia linkHref="example.com"></drupalMedia>
</htmlDiv>

❌ Actual result

What actually happens is:

<htmlDivParagraph>
  <drupalMedia linkHref="example.com"></drupalMedia>
</htmlDivParagraph>

Which is later on reduced to since <drupalMedia> is a block element:

<drupalMedia linkHref="example.com"></drupalMedia>

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

@lauriii lauriii added the type:bug This issue reports a buggy (incorrect) behavior. label Mar 24, 2022
@wimleers
Copy link

Sibling Drupal issue: https://www.drupal.org/project/drupal/issues/3271418

@Reinmar Reinmar added the squad:core Issue to be handled by the Core team. label Mar 24, 2022
@Reinmar
Copy link
Member

Reinmar commented Apr 20, 2022

Currently, to detect whether a <div> is a block-like element or a contrainer, we're scanning only the immediate children of that <div> element.

Thus, in this situation:

<div>
	<a><drupal-media/></a>
</div>

We're seeing only the <a> element and make the decision that the <div> should be a block-like element. Then, <drupal-media> is being converted, it's not allowed in <htmlDivParagraph> so <htmlDivParagraph> is stripped.

This means that we put more emphasize on the inner most elements than on the containers when deciding which elements to retain in case of schema conflicts.

Thus, the heuristic should also take into consideration the inner most elements when making the decision.

Why this makes sense will be visible in this scenario where invalid HTML is loaded:

<div>
	<span><p>xxx</p></span>
</div>

Currently, the editor will retain: <p><span>xxx</span></p>.

If we change the heuristic to scan the entire subtree (all nodes in it), the original structure will be better retained. We can expect something like:

<div>
	<p><span>xxx</span></p>
</div>

Note: we need to scan really all nodes in this tree. If we focused on the leaf nodes only, then the below markup would still not be handled correctly:

<div>
	<p><span>xxx</span></p>
</div>

@Reinmar
Copy link
Member

Reinmar commented Apr 20, 2022

The heuristic:

_hasBlockContent( viewElement ) {
const blockElements = this.editor.editing.view.domConverter.blockElements;
return Array.from( viewElement.getChildren() )
.some( node => blockElements.includes( node.name ) );
}

@CKEditorBot CKEditorBot added the status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. label Apr 25, 2022
@arkflpc arkflpc self-assigned this Apr 25, 2022
@CKEditorBot CKEditorBot added status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. and removed status:planned Set automatically when an issue lands in the "Sprint backlog" column. We will be working on it soon. labels Apr 25, 2022
oleq added a commit that referenced this issue Apr 29, 2022
…ck-elements

Fix (html-support): `<div>` elements should be upcast to container-like elements when there is a block among their descendants. Closes #11513.
@CKEditorBot CKEditorBot removed the status:in-progress Set automatically when an issue lands in the "In progress" column. We are working on it. label Apr 29, 2022
@CKEditorBot CKEditorBot added this to the iteration 53 milestone Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package:html-support squad:core Issue to be handled by the Core team. type:bug This issue reports a buggy (incorrect) behavior.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants