Ckeditor4: HTML5 transparent content model support - block-level links

Created on 15 Jun 2017  路  2Comments  路  Source: ckeditor/ckeditor4

Are you reporting a feature or a bug?

Feature Request - to extend support for HTML 5 markup

Provide detailed reproduction steps (if any)

  1. Create a static html page with latest CKEditor.
  2. In script, set the editor to allow all content viz. config.allowedContent = true
  3. Load the html page in a browser and switch to '_source_' mode
  4. Enter the following HTML 5 compliant markup:
    <a href="#"><div class="a">something in A </div><div lass="b">some thing in B</div></a>
  5. Switch to _WYSIWYG_ mode and then back to _source_ mode
  6. Note that the markup is no longer the same but has been transformed to :
    <div class="a"><a href="#">something in A </a></div>

Expected result

<a href="#"><div class="a">something in A </div></a>

Actual result

<div class="a"><a href="#">something in A </a></div>

References

Other details

This behavior has been noted in stackover flow

  • Browser: Any
  • OS: Any
  • CKEditor version: 4.1+
  • Installed CKEditor plugins: default
confirmed feature

Most helpful comment

In your config.js file, add in the following config setting:

// Display all children elements allowed in a <a> element.
console.log(CKEDITOR.dtd[ 'a' ]);

// Simply redefine DTD like this:
CKEDITOR.dtd['a']['div'] = 1;
CKEDITOR.dtd['a']['p'] = 1;
CKEDITOR.dtd['a']['i'] = 1;
CKEDITOR.dtd['a']['span'] = 1;

// Check if <div> can be contained in a <p> element.
console.log( !!CKEDITOR.dtd[ 'a' ][ 'div' ] ); // default false

// Check if <a> can be contained in a <div> element.
console.log( !!CKEDITOR.dtd[ 'div' ][ 'a' ] ); // default true

For Drupal 8, you can add this code into your admin theme js, not the best solution but functional

All 2 comments

I have limited the scope of this issue so that it is better defined.

There will be a challenge with that, as we currently use a static DTD, while solving this issue will require from us using a context-aware model determination.

In your config.js file, add in the following config setting:

// Display all children elements allowed in a <a> element.
console.log(CKEDITOR.dtd[ 'a' ]);

// Simply redefine DTD like this:
CKEDITOR.dtd['a']['div'] = 1;
CKEDITOR.dtd['a']['p'] = 1;
CKEDITOR.dtd['a']['i'] = 1;
CKEDITOR.dtd['a']['span'] = 1;

// Check if <div> can be contained in a <p> element.
console.log( !!CKEDITOR.dtd[ 'a' ][ 'div' ] ); // default false

// Check if <a> can be contained in a <div> element.
console.log( !!CKEDITOR.dtd[ 'div' ][ 'a' ] ); // default true

For Drupal 8, you can add this code into your admin theme js, not the best solution but functional

Was this page helpful?
0 / 5 - 0 ratings