Wrapping content in anchor tags with CKEditor I am trying to wrap a block of HTML content in an  tag in a Drupal 8 installation:

&lt;a href="/link"&gt;&lt;h2&gt;Link 1&lt;/h2&gt;&lt;h3&gt;Subheader link 1&lt;/h3&gt;&lt;/a&gt;


CKEditor changes it to:

&lt;h2&gt;&lt;a href="/link"&gt;Link 1&lt;/a&gt;&lt;/h2&gt;&lt;h3&gt;&lt;a href="/link"&gt;Subheader link 1&lt;/a&gt;&lt;/h3&gt;


The Limit allowed HTML tags I have set are:

&lt;div class id&gt; &lt;p class id&gt; &lt;img class id&gt; &lt;a href hreflang class id&gt; &lt;em&gt; &lt;strong&gt; &lt;cite class id&gt; &lt;blockquote cite cla&gt; &lt;code&gt; &lt;ul type class id&gt; &lt;ol start type class id&gt; &lt;li class id&gt; &lt;dl class id&gt; &lt;dt class id&gt; &lt;dd&gt; &lt;h2 class id&gt; &lt;h3 class id&gt; &lt;h4 class id&gt; &lt;h5 class id&gt; &lt;h6 class id&gt; &lt;s&gt; &lt;sup&gt; &lt;sub&gt; &lt;img src alt data-entity-type data-entity-uuid data-align data-caption class id&gt; &lt;table class id&gt; &lt;caption class id&gt; &lt;tbody class id&gt; &lt;thead class id&gt; &lt;tfoot class id&gt; &lt;th class id&gt; &lt;td class id&gt; &lt;tr class id&gt; &lt;hr class id&gt; &lt;p class id&gt; &lt;h1 class id&gt; &lt;pre class id&gt;&lt;section class id&gt;&lt;header class id&gt; &lt;a div&gt; &lt;a span&gt;


How can I wrap content in an anchor tag with CKEditor?
I found a solution. As @Clive said CKEDITOR.dtd.a.h2 = 1; and CKEDITOR.dtd.a.h3 = 1; is the solution.
These need to be declared in a my_module.module file:
function my_module_editor_js_settings_alter(array &amp;$settings) {

  foreach (array_keys($settings['editor']['formats']) as $text_format_id) {
    if ($settings['editor']['formats'][$text_format_id]['editor'] === 'ckeditor') {
        $settings['editor']['formats'][$text_format_id]['editorSettings']['customConfig'] = 
        base_path() . drupal_get_path('module', 'my_module') . '/ckeditor_config.js';
}
  }
}

And then we create a file ckeditor_config.js:
CKEDITOR.dtd['a']['h2'] = 1;
CKEDITOR.dtd['a']['h3'] = 1;

Doing this we can wrap h2 and h3 elements with an anchor tag and CKEditor is not going to modify it.