Reputation: 647
I try new CKEditor 4 because code correction in version 3.6 can't accept HTML 5 valid code like this:
<a href="#"><p>something</p></a>
But new CKEditor version still repair this code, so where is problem? Is necessary to set HTML 5 as default in config?
Upvotes: 4
Views: 4350
Reputation: 11
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
Upvotes: 1
Reputation: 12176
For future people coming to this with the same issue, I did come up with a solution but I'm not overly happy about it as there should be an option for this as it's PERFECTLY valid in HTML5
In your config.js
file, add in the following config setting:
config.protectedSource.push(/[\r|\n]|(<a([^*>]+>)|<\/a>)/g);
Here's a demo of the regex working: DEMO
Basically all we're doing here is:
\r
\n
<a
followed by an text until we come to >
- (<a([^*>]+>)
<\/a>
This regex will stop validing the found results, I'm sure there's a better way to do this as I'm not regexPERT (<-- good at puns though!)
This should disable the UI for editing anchors in wysiwyg mode. This fixed worked for me because the editors I'm adding this to are fixed in source mode, so this is fine for this purpose.
config.allowedContent = true;
config.fullPage = false;
Hope this helps
Upvotes: 4
Reputation: 1
There is a workable way around this using xsl to map any unknown element to either a div or a span-tag using the original element as classname, and then reverse this onsubmit. We do that all the time from and back to xml, and it works just fine.
Upvotes: 0
Reputation: 15895
Nope. CKEditor parsers are using static DTD. HTML5 cannot be described with static DTD so at the moment CKEditor cannot support this kind of markup.
See the ticket to know more.
Upvotes: 6