Skip to content

Alignment Plugin

The AlignmentPlugin adds text alignment support for paragraphs, headings, and other alignable block types.

Text alignment options

import { AlignmentPlugin } from '@notectl/core';
new AlignmentPlugin()
// or restrict alignments:
new AlignmentPlugin({ alignments: ['left', 'center', 'right'] })
interface AlignmentConfig {
/** Enabled alignment options. Default: ['left', 'center', 'right', 'justify'] */
readonly alignments: readonly BlockAlignment[];
/** Block types that support alignment. Default: ['paragraph', 'heading', 'title', 'subtitle', 'table_cell', 'image'] */
readonly alignableTypes: readonly string[];
/** Per-type default alignment. E.g. { image: 'center' } */
readonly defaults: Readonly<Record<string, BlockAlignment>>;
/** Render separator after toolbar item. */
readonly separatorAfter?: boolean;
}
type BlockAlignment = 'left' | 'center' | 'right' | 'justify';
new AlignmentPlugin({
alignments: ['left', 'center', 'right'],
})
new AlignmentPlugin({
alignableTypes: ['paragraph', 'heading', 'blockquote'],
})
CommandDescriptionReturns
alignLeftAlign text leftboolean
alignCenterCenter textboolean
alignRightAlign text rightboolean
alignJustifyJustify textboolean
editor.executeCommand('alignCenter');
editor.executeCommand('alignLeft');
ShortcutAction
Ctrl+Shift+L / Cmd+Shift+LAlign left
Ctrl+Shift+E / Cmd+Shift+EAlign center
Ctrl+Shift+R / Cmd+Shift+RAlign right
Ctrl+Shift+J / Cmd+Shift+JJustify

The alignment plugin renders as a dropdown button with alignment icons. The currently active alignment is highlighted. Only alignments listed in the alignments config appear in the dropdown.

The plugin registers transaction middleware that preserves the align attribute when a block’s type changes (e.g., paragraph to heading). This ensures alignment survives block type transformations.

The plugin patches existing node specs to add an align attribute:

AttributeTypeDefaultRenders As
alignstring'left'style="text-align: center"

When alignment is 'left' (the default), no inline style is added to keep the DOM clean.