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.
# Installation
This feature is enabled by default in the superbuild only.
To add this feature to your rich-text editor, install the @ckeditor/ckeditor5-html-support
package:
npm install --save @ckeditor/ckeditor5-html-support
Then add it to the editor configuration:
import { HtmlComment } from '@ckeditor/ckeditor5-html-support';
ClassicEditor
.create( document.querySelector( '#editor' ), {
plugins: [ HtmlComment, ... ],
} )
.then( ... )
.catch( ... );
Read more about installing plugins.
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.