Configuration

When creating an editor in your page, it is possible to set up configurations that change many of its aspects. For example:

  1. ClassicEditor
  2. .create( document.querySelector( '#editor' ), {
  3. toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
  4. heading: {
  5. options: [
  6. { model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
  7. { model: 'heading1', view: 'h1', title: 'Heading 1', class: 'ck-heading_heading1' },
  8. { model: 'heading2', view: 'h2', title: 'Heading 2', class: 'ck-heading_heading2' }
  9. ]
  10. }
  11. } )
  12. .catch( error => {
  13. console.log( error );
  14. } );

As you can see, configurations are set by a simple JavaScript object passed to the create() method.

Removing features

Builds come with all features included in the distribution package enabled by default. They are defined as plugins for CKEditor.

In some cases, you may need to have different editor setups in your application, all based on the same build. For that purpose, you need to control the plugins available in the editor at runtime.

In the example below Heading and Link plugins are removed:

  1. // Remove a few plugins from the default setup.
  2. ClassicEditor
  3. .create( document.querySelector( '#editor' ), {
  4. removePlugins: [ 'Heading', 'Link' ],
  5. toolbar: [ 'bold', 'italic', 'bulletedList', 'numberedList', 'blockQuote' ]
  6. } )
  7. .catch( error => {
  8. console.log( error );
  9. } );

Be careful when removing plugins from CKEditor builds using config.removePlugins. If removed plugins were providing toolbar buttons, the default toolbar configuration included in a build will become invalid. In such case you need to provide the updated toolbar configuration as in the example above.

List of plugins

Each build has a number of plugins available. You can easily list all plugins available in your build:

  1. ClassicEditor.builtinPlugins.map( plugin => plugin.pluginName );

Adding features

Adding complex features

As CKEditor builds do not include all possible features, the only way to add more features to them is to create a custom build.

Adding simple (standalone) features

There is an exception to every rule. Although it is impossible to add plugins that have dependencies to @ckeditor/ckeditor5-core or @ckeditor/ckeditor5-engine (that includes nearly all existing official plugins) without rebuilding the build, it is still possible to add simple, dependency-free plugins.

You can do that using the config.extraPlugins configuration. The plugin interface allows plugins to be simple functions and you can define them in just a few lines, for instance:

  1. function MyPlugin( editor ) {
  2. // ...
  3. }

or

  1. class MyPlugin {
  2. constructor( editor ) {
  3. // ...
  4. }
  5. init() {
  6. // ...
  7. }
  8. }

An example plugin that you may want to add this way is a custom upload adapter.

  1. import ClassicEditor from '@ckeditor/ckeditor5-build-classic';
  2. function MyUploadAdapterPlugin( editor ) {
  3. editor.plugins.get( 'FileRepository' ).createUploadAdapter = function( loader ) {
  4. // ...
  5. };
  6. }
  7. // Load the custom upload adapter as a plugin of the editor.
  8. ClassicEditor
  9. .create( document.querySelector( '#editor' ), {
  10. extraPlugins: [ MyUploadAdapterPlugin ],
  11. // ...
  12. } )
  13. .catch( error => {
  14. console.log( error );
  15. } );

Toolbar setup

In builds that contain toolbars an optimal default configuration is defined for it. You may need a different toolbar arrangement, though, and this can be achieved through configuration.

Each editor may have a different toolbar configuration scheme, so it is recommended to check its documentation. In any case, the following example may give you a general idea:

  1. ClassicEditor
  2. .create( document.querySelector( '#editor' ), {
  3. toolbar: [ 'bold', 'italic', 'link' ]
  4. } )
  5. .catch( error => {
  6. console.log( error );
  7. } );

The above is a strict UI-related configuration. Removing a toolbar item does not remove the feature from the editor internals. If your goal with the toolbar configuration is to remove features, the right solution is to also remove their respective plugins. Check Removing features above for more information.

Listing available items

You can use the following snippet to retrieve all toolbar items available in your editor:

  1. Array.from( editor.ui.componentFactory.names() );

Other configuration options

See EditorConfig to learn about all available configuration options.

Some of the options may require loading plugins which are not available in the build you use. Read more about customizing builds.