HTML comment element
By default, the editor filters out all HTML comments on initialization. The HtmlComment
feature lets developers keep HTML comments in the document without displaying them to the user.
The HTML comments feature is experimental and not yet production-ready.
The support for HTML comments is at the basic level so far - see the known issues section below.
# Demo
The editor below is configured to keep HTML comments in the document content. You can view the source of the document using the source editing feature. Toggle the source editing mode to see there is an HTML comment in the document source. Try uncommenting the paragraph below the picture. Once you leave the source editing mode, you will see this paragraph in the editable area.
The great things you learn from traveling
Appreciation of diversity
Getting used to an entirely different culture can be challenging. While it’s also nice to learn about cultures online or from books, nothing comes close to experiencing cultural diversity in person. You learn to appreciate each and every single one of the differences while you become more culturally fluid.
# Installation
⚠️ New import paths
Starting with version 42.0.0, we changed the format of import paths. This guide uses the new, shorter format. Refer to the Packages in the legacy setup guide if you use an older version of CKEditor 5.
To add this feature to your rich-text editor, install the @ckeditor/ckeditor5-html-support
package:
This package is part of our open-source aggregate package.
npm install ckeditor5
Then add it to the editor configuration:
import { HtmlComment } from 'ckeditor5';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ HtmlComment, ... ],
} )
.then( ... )
.catch( ... );
HTML comment feature does not require any configuration.
# Known issues
The main issue with the HTML comments feature is that comments can be easily repositioned or lost in various cases #10118, #10119. Also copying and pasting (or dragging and dropping) elements containing HTML comments within the editor does not work as expected #10127.
We are open for feedback, so if you find any issue, feel free to report it in the main CKEditor 5 repository.
# Related features
CKEditor 5 has other features related to HTML editing you may want to check:
- Source editing – Provides the ability for viewing and editing the source of the document. When paired, these two plugins let the user gain powerful control over the content editing.
- HTML embed – Allows embedding an arbitrary HTML snippet in the editor. It is a more constrained and controllable approach to arbitrary HTML than GHS.
# Contribute
The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-html-support.
Every day, we work hard to keep our documentation complete. Have you spotted outdated information? Is something missing? Please report it via our issue tracker.
With the release of version 42.0.0, we have rewritten much of our documentation to reflect the new import paths and features. We appreciate your feedback to help us ensure its accuracy and completeness.