The CKEditor 5 Block Quote package provides comprehensive block quote functionality for the CKEditor 5 rich text editor. It enables users to format text as quotations with proper semantic HTML <blockquote> elements, complete with editing capabilities, UI integration, and keyboard interaction support.
npm install @ckeditor/ckeditor5-block-quote (or included in main ckeditor5 package)import { BlockQuote, BlockQuoteEditing, BlockQuoteUI, BlockQuoteCommand } from '@ckeditor/ckeditor5-block-quote';From main ckeditor5 package:
import { BlockQuote, BlockQuoteEditing, BlockQuoteUI, BlockQuoteCommand } from 'ckeditor5';For CommonJS:
const { BlockQuote } = require('@ckeditor/ckeditor5-block-quote');Core CKEditor 5 types referenced in the API:
Core types from CKEditor 5 framework:
// From '@ckeditor/ckeditor5-core'
interface Editor {
commands: CommandCollection;
model: Model;
editing: EditingController;
ui: EditorUI;
execute(commandName: string, ...args: any[]): any;
}
abstract class Plugin {
readonly editor: Editor;
constructor(editor: Editor);
init?(): void;
destroy?(): void;
static get requires?(): Array<typeof Plugin>;
static get pluginName?(): string;
static get isOfficialPlugin?(): boolean;
}
abstract class Command {
readonly editor: Editor;
isEnabled: boolean;
value: any;
constructor(editor: Editor);
refresh(): void;
execute(...args: any[]): void;
}
// From '@ckeditor/ckeditor5-enter'
class Enter extends Plugin {
static get pluginName(): 'Enter';
}
// From '@ckeditor/ckeditor5-typing'
class Delete extends Plugin {
static get pluginName(): 'Delete';
}import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
ClassicEditor
.create(document.querySelector('#editor')!, {
plugins: [Essentials, Paragraph, BlockQuote],
toolbar: ['blockQuote']
})
.then(editor => {
// Execute block quote command programmatically
editor.execute('blockQuote');
// Check if selection is in a block quote
const command = editor.commands.get('blockQuote')!;
console.log('Is in block quote:', command.value);
})
.catch(error => {
console.error(error);
});The CKEditor 5 Block Quote package follows the standard CKEditor 5 plugin architecture:
The primary entry point that combines all block quote functionality into a single, easy-to-use plugin.
/**
* The main block quote plugin that loads editing and UI features
*/
export class BlockQuote extends Plugin {
/** Required plugins: BlockQuoteEditing and BlockQuoteUI */
static get requires(): readonly [typeof BlockQuoteEditing, typeof BlockQuoteUI];
/** Plugin name identifier */
static get pluginName(): 'BlockQuote';
/** Official CKEditor 5 plugin flag */
static override get isOfficialPlugin(): true;
}Handles the core editing functionality including model schema, view conversions, and keyboard interactions.
/**
* Block quote editing plugin that handles model/view logic and keyboard behaviors
*/
export class BlockQuoteEditing extends Plugin {
/** Plugin name identifier */
static get pluginName(): 'BlockQuoteEditing';
/** Official CKEditor 5 plugin flag */
static override get isOfficialPlugin(): true;
/** Required plugins for keyboard handling */
static get requires(): readonly [typeof Enter, typeof Delete];
/** Initialize the editing features */
init(): void;
}The init() method sets up:
Provides user interface components including toolbar buttons and menu items.
/**
* Block quote UI plugin that provides toolbar and menu components
*/
export class BlockQuoteUI extends Plugin {
/** Plugin name identifier */
static get pluginName(): 'BlockQuoteUI';
/** Official CKEditor 5 plugin flag */
static override get isOfficialPlugin(): true;
/** Initialize UI components */
init(): void;
}The init() method creates:
Implements the command logic for applying and removing block quotes from selected content.
/**
* Block quote command that handles applying and removing block quotes
*/
export class BlockQuoteCommand extends Command {
/** Whether the selection starts in a block quote (observable, readonly) */
declare public value: boolean;
/** Updates command state based on current selection */
override refresh(): void;
/** Executes the command to apply or remove block quotes */
override execute(options?: BlockQuoteCommandExecuteOptions): void;
}
interface BlockQuoteCommandExecuteOptions {
/** If set, forces command behavior: true=apply, false=remove, undefined=toggle */
forceValue?: boolean;
}Command Behavior:
value is false: Wraps selected blocks in block quotesvalue is true: Removes block quote formatting from selected blocksUsage Examples:
// Toggle block quote (default behavior)
editor.execute('blockQuote');
// Force apply block quote
editor.execute('blockQuote', { forceValue: true });
// Force remove block quote
editor.execute('blockQuote', { forceValue: false });
// Check current state
const command = editor.commands.get('blockQuote');
console.log('Selection in block quote:', command.value);
console.log('Command enabled:', command.isEnabled);Extends CKEditor 5 core type definitions to include block quote plugin and command types.
declare module '@ckeditor/ckeditor5-core' {
interface PluginsMap {
[BlockQuote.pluginName]: BlockQuote;
[BlockQuoteEditing.pluginName]: BlockQuoteEditing;
[BlockQuoteUI.pluginName]: BlockQuoteUI;
}
interface CommandsMap {
blockQuote: BlockQuoteCommand;
}
}The block quote feature registers a 'blockQuote' element in the model schema with the following properties:
$container - can contain other block elements<blockquote> elementThe plugin provides enhanced keyboard behavior within block quotes:
The package includes default CSS styling for block quotes:
.ck-content blockquote {
overflow: hidden;
padding-right: 1.5em;
padding-left: 1.5em;
margin-left: 0;
margin-right: 0;
font-style: italic;
border-left: solid 5px hsl(0, 0%, 80%);
}
.ck-content[dir="rtl"] blockquote {
border-left: 0;
border-right: solid 5px hsl(0, 0%, 80%);
}The editing plugin includes automatic post-fixing for invalid block quote states:
import { ClassicEditor } from '@ckeditor/ckeditor5-editor-classic';
import { BlockQuote } from '@ckeditor/ckeditor5-block-quote';
import { Essentials } from '@ckeditor/ckeditor5-essentials';
import { Paragraph } from '@ckeditor/ckeditor5-paragraph';
ClassicEditor
.create(document.querySelector('#editor')!, {
plugins: [Essentials, Paragraph, BlockQuote],
toolbar: ['blockQuote']
})
.catch(error => {
console.error(error);
});// Apply block quote to current selection
editor.execute('blockQuote');
// Listen for command state changes
const command = editor.commands.get('blockQuote');
command.on('change:value', () => {
console.log('Block quote state changed:', command.value);
});
// Check if command is available
if (command.isEnabled) {
editor.execute('blockQuote');
}