Show blocks
The show blocks feature allows the content creators to visualize all block-level elements (except for widgets). It surrounds them with an outline and displays their element name in the top-left corner of the box.
# Demo
Toggle the block elements visibility with the show block export to PDF and export to Word features, so there is no need to remove them before exporting.
toolbar button to see the feature in action. The content remains editable, so you can see how the blocks adjust to the content structure on the go. These outlines are not visible in theThis demo presents a limited set of features. Visit the feature-rich editor example to see more in action.
# Installation
The show blocks feature is enabled by default in the superbuild only.
To add this feature to your editor, install the @ckeditor/ckeditor5-show-blocks
package:
npm install --save @ckeditor/ckeditor5-show-blocks
Then add the ShowBlocks
plugin to your plugin list and to the toolbar:
import { ShowBlocks } from '@ckeditor/ckeditor5-show-blocks';
ClassicEditor
.create( document.querySelector( '#editor' ), {
// Load the plugin.
plugins: [ ShowBlocks, /* ... */ ],
// Display the "Show blocks" button in the toolbar.
toolbar: [ 'showBlocks', /* ... */ ],
} )
.then( /* ... */ )
.catch( /* ... */ );
Read more about installing plugins and toolbar configuration.
# Known issues
- The show blocks feature does not support widgets yet. It means it will currently not show block outlines, for example, for images or tables.
- At present, the show blocks feature is not yet fully compatible with the pagination feature. Using these two together may result in errors.
# Related features
Other CKEditor 5 features related to HTML editing that you may want to check:
- General HTML Support – Allows you to enable HTML features (elements, attributes, classes, styles) that are not supported by other dedicated CKEditor 5 plugins.
- Source editing – Provides the ability for viewing and editing the source of the document.
- Full page HTML – Allows using CKEditor 5 to edit entire HTML pages, from
<html>
to</html>
, including the page metadata.
# Common API
The ShowBlocks
plugin registers the 'showBlocks'
UI button component and the 'showBlocks'
command implemented by ShowBlocksCommand
.
You can execute the command using the editor.execute()
method:
// Toggle the visibility of block-level elements outline.
editor.execute( 'showBlocks' );
We recommend using the official CKEditor 5 inspector for development and debugging. It will give you tons of useful information about the state of the editor such as internal data structures, selection, commands, and many more.
# Contribute
The source code of the feature is available on GitHub at https://github.com/ckeditor/ckeditor5/tree/master/packages/ckeditor5-show-blocks.
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.