Here is a little code snippet to be added in a .module file.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
/** * Implements hook_editor_js_settings_alter(). * * {@inheritdoc} */ function MODULE_editor_js_settings_alter(array &$settings) { foreach ($settings['editor']['formats'] as $name => $value) { // Use <br> instead of <p> on enter. // See: https://docs.ckeditor.com/ckeditor4/latest/api/CKEDITOR.html#property-ENTER_BR. // CKEditor natively converts double <br> into <p> on rendering. $settings['editor']['formats'][$name]['editorSettings']['enterMode'] = '2'; } } |
Additional Information
- Instructions made on Drupal 8.5.x.
- Will break text align buttons in the CKEditor toolbar: Issue on Drupal.org
- The default behaviour of CKEditor is the following:
- Enter: inserts a paragraph directly in the WYSIWYG,
- Shift + Enter: inserts a line break.
- The new behaviour of CKEditor with the hook will be:
- Enter: inserts a single line break (br),
- 2 × Enter: inserts two line breaks which will be converted into a paragraph when rendered.