How to make CKeditor format code indenting elements and adding line breaks? Using CKEditor in Drupal 7, I could configure CKEditor to format the code adding line breaks and indenting the HTML code automatically. 

For example, pasting this in the source code:

&lt;div class="row"&gt;&lt;div class="col-md-12"&gt;Test&lt;/div&gt;&lt;/div&gt;


CKEditor could be configured to turn it into:

&lt;div class="row"&gt;
    &lt;div class="col-md-12"&gt;
        Test
    &lt;/div&gt;
&lt;/div&gt;


To achieve that, I just had to select the right configuration for CKEditor (Indent the element contents, Break line before the opening tag,  Break line after the closing tag), and include the Javascript configuration:

config.allowedContent = true;


But in Drupal 8, I can't see those options and CKEditor removes all the whitespace from the source code.

How can I make CKEditor work like with that configuration in Drupal 8?
Finally I found a solution, thanks to the post CKEditor with well-formatted html source code.

I just added to a custom module the following code:

function mymodule_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', 'mymodule') . '/ckeditor_config.js';           
    }
  }        
}


to include a configuration a file called ckeditor_config.js that contains the code:

CKEDITOR.on('instanceReady', function(ev) {
    // Sets indentation of source code
    ev.editor.dataProcessor.writer.setRules( 'div', {
                indent: true,
                breakBeforeOpen: true,
                breakAfterOpen: true,
                breakBeforeClose: true,
                breakAfterClose: true
            });
});


Doing this, CKEditor will keep the indentations in the source code, and a well formatted code easy to read.