Wrapping div and p elements in anchor tags with CKEditor

Created on 4 April 2023, over 1 year ago
Updated 5 April 2023, over 1 year ago

Problem/Motivation

As of HTML 5 anchor tags can contain block-level elements but CKEditor 4 does not support (some?) HTML 5 concepts.

Before CKEditor 4 was separated to a contrib module (drupal 8) the solution was to add

CKEDITOR.dtd['a']['div'] = 1;
CKEDITOR.dtd['a']['p'] = 1;

(source https://drupal.stackexchange.com/questions/252058/wrapping-content-in-an..., https://stackoverflow.com/questions/19825802/how-to-configure-ckeditor-t...)
but this no longer seems to work.

Is there a reason the above fix is not working?
Can we make the HTML 5 anchor work in some other way?

I would like to be able to wrap div and p elements in anchor tags with CKEditor.

Steps to reproduce

Edit a CKEditor field.
Go to source and type <a href="#"><p>Lorem ipsum</p></a>
Go to view mode and back to source.
The result is

<p>&nbsp;</p>
<p><a href="#">Lorem ipsum</a></p>
<p>&nbsp;</p>
💬 Support request
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024