Skip to content

Alignment Plugin

The AlignmentPlugin adds text alignment support for paragraphs, headings, and other alignable block types. It uses logical alignment values (start/end) instead of physical values (left/right) for correct behavior in both LTR and RTL text directions.

Text alignment options

import { AlignmentPlugin } from '@notectl/core/plugins/alignment';
new AlignmentPlugin()
// or restrict alignments:
new AlignmentPlugin({ alignments: ['start', 'center', 'end'] })
interface AlignmentConfig {
/** Enabled alignment options. Default: ['start', 'center', 'end', '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>>;
/** Custom locale strings. */
readonly locale?: AlignmentLocale;
}
type BlockAlignment = 'start' | 'center' | 'end' | 'justify';

The plugin uses CSS logical values instead of physical directions:

Logical ValueIn LTRIn RTL
startLeft-alignedRight-aligned
endRight-alignedLeft-aligned
centerCenteredCentered
justifyJustifiedJustified

This ensures alignment works correctly regardless of text direction. When combined with the TextDirectionPlugin, alignment automatically adapts to the block’s direction.

new AlignmentPlugin({
alignments: ['start', 'center', 'end'],
})
new AlignmentPlugin({
alignableTypes: ['paragraph', 'heading', 'blockquote'],
})
CommandDescriptionReturns
alignStartAlign text to start (left in LTR, right in RTL)boolean
alignCenterCenter textboolean
alignEndAlign text to end (right in LTR, left in RTL)boolean
alignJustifyJustify textboolean
editor.executeCommand('alignCenter');
editor.executeCommand('alignStart');
ShortcutAction
Ctrl+Shift+L / Cmd+Shift+LAlign start
Ctrl+Shift+E / Cmd+Shift+EAlign center
Ctrl+Shift+R / Cmd+Shift+RAlign end
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'start'style="text-align: center"

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