CKEditor5

As of 11/1/2023, CKEditor 5 is now what is installed in all Drupal sites.

CKEditor 5 is a widely-used WYSIWYG text editor tailored for web applications. When incorporating CKEditor 5 with content management systems like Drupal, understanding its interaction with filters such as the Basic HTML Filter and Full HTML Filter becomes essential. This knowledge base page sheds light on the primary differences and compatibility of CKEditor 5 with these filters, offering insights into its functionality for content filtering and security within the context of web development.


CKEditor 5 and Basic HTML Filter

  1. Modularity: CKEditor 5 is more modular and modern. It allows easy integration with various filters, including the Basic HTML Filter.

  2. Security: CKEditor 5, when used with the Basic HTML Filter, offers enhanced security features, making it more robust against security threats by filtering out potentially harmful code by default.

  3. Customization: CKEditor 5 provides a flexible configuration system, enabling users to customize the editor's toolbar and behavior. This makes it easier to tailor the editor to specific needs.

  4. Accessibility: CKEditor 5 has improved accessibility features out of the box, making it a better choice for ensuring that the content created is accessible to all users.


CKEditor 5 and Full HTML Filter

  1. Advanced Editing: CKEditor 5 can be integrated with the Full HTML Filter for users who need advanced content editing capabilities. It allows the use of complex HTML but with enhanced security features.

  2. Security Enhancements: CKEditor 5, when combined with the Full HTML Filter, maintains a higher level of security. It mitigates security risks by providing better filtering and validation of user input.

  3. Customization: CKEditor 5 offers extensive customization options for the Full HTML Filter, allowing administrators to define which HTML elements and attributes are allowed, further enhancing content control.


CKEditor 5 Table Styles

Bootstrap is a popular front-end framework that provides a set of pre-designed styles and components to help you create responsive and visually appealing web applications. Out of the box, CKEditor5 did not have options for Table Styles. Here at Drupal ITS, we included several table styles Bootstrap provided: table-striped, table-small, table-bordered, and table-responsive.

Table Striped

The table-striped class in Bootstrap adds zebra-striping to a table, which alternates the background color of rows to make the table easier to read.

Table Small

The table-small class in Bootstrap condenses the size of the table.

Table Bordered

The table-bordered class adds borders, making it visually distinct from the surrounding content.

Table Responsive

The table-responsive class makes tables horizontally scrollable on smaller screens to ensure the entire table is visible without the need for zooming or horizontal scrolling.

A table should only be wrapped by a registered parent div element in CKEditor5, such as div.table-responsive. Any other wrapper will break the table toolbar in the CKEditor5 view. For a new table div wrapper, please contact Drupal ITS for further enhancements.

<div class="table-responsive"> <table class="table" data-responsive="enabled"> <!-- Your table content goes here --> </table> </div>

These Bootstrap table styles can be used individually or combined to enhance tabular data presentation in your web application.

Inline Images

It is recommended that you use Paragraph Bundles when dealing with content that has images, as your page’s layout will be more consistent. However, you can upload inline images directly inside CKEditor to add alongside body text.

Uploading Inline Images

  • Available in Text blocks that load the CKEditor

  • Click on the Image button in the toolbar. 

    • Looks like a photo.

  • You will be prompted to upload an image file.

    • Images must be smaller than 5 MB

  • The alternative text field is required

  • Align field is available to set how text wraps around the image

    • Stylings and margins for image alignment will be improved in future CFW3 releases

  • You can make basic changes to an uploaded image by double-clicking on the image to bring up the Image Properties toolbar.

    • Available properties in this modal are very limited, and you will not have access to certain fields (width, height, class) as in CFW2.

  • Inline images uploaded in this manner are added to the files managed by Drupal

  • Images are uploaded to an /inline-images directory on your website

Inline Image Placement

  • Hover over the image in the editor to locate the move handle in the image's upper left corner.

  • Your cursor will change to a move icon.

  • Click, drag, and release the cursor to your desired location alongside your body text.

Resizing Inline Images

For the best results, it is recommended that your image is already saved at your desired size before you upload. However, you can resize your image in the editor.

  • Hover over the image in the editor to locate the resize handle found in the lower corner of the image itself.

  • Your cursor will change to a resize icon

  • Click, drag, and release the handle to your desired dimensions.

  • The modal Image Properties popup for an image does not have width and height fields available due to a Drupal 9 limitation.

  • Any specific image dimensions must be made directly in the HTML source

Aligning Inline Images

  • Double-click on the image to bring up an Image toolbar.

  • Select one of the Align options: None, Left, Center, Right

    • Stylings and margins for image alignment will be improved in future CFW3 releases

Offsite Images

If you are embedding an image that has not been uploaded via CKEditor as above, you will not benefit from CKEditor’s image toolbar and features. This is due to Drupal 9’s CKEditor file management integration. 

You will not see any image handles, nor will you be able to bring up the Image toolbar.

All width, height, and placement edits must be made inside the source HTML. An example of an offsite image might be an image for a logo that isn’t hosted on your website or an image that was uploaded on a separate webpage.

Inline Files

Uploading Inline Files

  • You should now see the Insert File button in the CKEditor5 toolbar when editing content.

  • Use the Insert File button to upload and insert files. You can select a blank space in Ckeditor5 to designate the file location or highlight text, then select the Insert File button to upload and insert files.

  • You will then be prompted to upload a file.

    • Files must be smaller than 5 MB

    • Allowed types: pdf doc docx xls xlsx txt.

Replace File

  • When replacing a file, select the text of the file you want to replace, you should now see the File Toolbar where there is a Replace file button.

  • Use the Replace file dialog window to Remove, then replace it with a new file. You must upload a file.


Delete File

  • When deleting a file, select the text of the file you want to delete, you should now see the File Toolbar where there is a Delete file button.

 

  • When the window prompts you, “Are you sure you want to delete this file?“ You can now either click OK to accept or Cancel.

Inserting Bootstrap Icons and Font Awesome Icons

  • When inserting icons, you should hard code the icons by switching to Source mode (Full HTML) in the CKEditor5 toolbar.

  • Once you are in Source mode. You can now hard code any Bootstrap Icon or Font Awesome Icon by wrapping it with a <p> tag and <em> tag and adding a %nbsp; inside the <i> tag. See below for an example.

  • To verify they are ‘sticky’, switch back to WYSIWYG mode, and the icon should be visible. Then switch to Source again and make sure the code is there.

Note: If no text is present (ie, only an icon), CKEditor removes everything. We believe this ‘design’ feature in CKEditor does not allow empty content.

Note: The &nbsp; is required inside the <i></i> tag, or CKEditor will remove the entire tag.

Line Break and Empty Paragraph Handling in CKEditor 5

In CKEditor5, the automatic insertion of <br> tags typically occurs due to the editor’s handling of line breaks and empty paragraphs. This behavior is part of the editor’s design to ensure proper formatting and a consistent user experience.

Three Reasons Why CKEditor5 does Automatic <br> Insertions:

Empty Paragraph Handling
CKEditor5 often inserts <br> tags in empty paragraphs to maintain consistency and ensure that empty lines are rendered properly.

Soft Line Breaks
When users press Shift+Enter, CKEditor5 inserts a <br> tag to create a line break within the same paragraph rather than ending the paragraph.

Browser Compatibility
Different browsers handle empty elements and line breaks in varying ways. CKEditor5 uses <br> tags to standardize this behavior across all browsers.