This plugin adds the ability to visualize all block-level elements in the editor by surrounding them with an outline and displaying their element name at the top-right. This is particularly useful for understanding the structure of your content and identifying different HTML elements.
If you are using a fat build of the editor, then the plugin is already included in it. If you are using the slim build, then you need to enable it manually:
CopyJodit.make('#editor', { extraPlugins: ['show-blocks'] });
boolean
false
Enables or disables the show blocks feature when the editor is initialized.
CopyJodit.make('#editor', { showBlocks: { enable: true } });
string
'#ccc'
Sets the color of the outlines and element names.
CopyJodit.make('#editor', { showBlocks: { color: '#ff0000' // Red outlines and element names } });
string[]
An array of HTML tag names that will be highlighted when the show blocks feature is enabled.
Default value includes most HTML elements:
Copy[ 'html', 'body', 'div', 'span', 'applet', 'object', 'iframe', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'pre', 'a', 'abbr', 'acronym', 'address', 'big', 'cite', 'code', 'del', 'dfn', 'em', 'img', 'ins', 'kbd', 'q', 's', 'samp', 'small', 'strike', 'strong', 'sub', 'sup', 'tt', 'var', 'b', 'u', 'i', 'center', 'dl', 'dt', 'dd', 'fieldset', 'form', 'label', 'legend', 'caption', 'th', 'td', 'li', 'ol', 'ul', 'article', 'aside', 'canvas', 'details', 'embed', 'figure', 'figcaption', 'footer', 'header', 'hgroup', 'menu', 'nav', 'output', 'ruby', 'section', 'summary', 'time', 'mark', 'audio', 'video' ]
You can customize this list to highlight only specific elements:
CopyJodit.make('#editor', { showBlocks: { tagList: ['p', 'div', 'h1', 'h2', 'h3', 'blockquote'] } });
The plugin registers the following commands that can be executed programmatically:
Enables the show blocks feature.
Copyconst editor = Jodit.make('#editor'); editor.execCommand('enableShowBlocks');
Disables the show blocks feature.
Copyconst editor = Jodit.make('#editor'); editor.execCommand('disableShowBlocks');
Toggles the show blocks feature on or off.
Copyconst editor = Jodit.make('#editor'); editor.execCommand('toggleShowBlocks');
Copyconst editor = Jodit.make('#editor', { buttons: ['showBlocks'], showBlocks: { enable: false, // Disabled by default color: '#ccc' } }); // Toggle show blocks when needed editor.execCommand('toggleShowBlocks');
Copyconst editor = Jodit.make('#editor', { buttons: ['bold', 'italic', '|', 'showBlocks'], showBlocks: { enable: true, // Enabled by default color: '#3498db', // Blue color tagList: ['p', 'div', 'h1', 'h2', 'h3', 'ul', 'ol', 'li'] // Only highlight these elements } });
Copyconst editor = Jodit.make('#editor', { toolbar: { items: [ 'source', '|', 'bold', 'italic', '|', 'ul', 'ol', '|', { group: 'view-options', buttons: ['showBlocks'] } ] }, showBlocks: { enable: false, color: '#27ae60' // Green color } });
This visual aid helps content creators understand the structure of their document and identify different HTML elements without having to view the source code.