Overview
Thehard-break extension adds support for hard line break nodes, which insert line breaks (<br>) within text blocks without creating a new paragraph. This is useful for addresses, poetry, or any content where you need line breaks within a single block.
Installation
Usage
API Reference
defineHardBreak()
Defines a hard break node with commands, keymap, and node specification. Returns:HardBreakExtension
This extension includes:
- Node specification
- Insert command
- Keyboard shortcuts
defineHardBreakSpec()
Defines only the hard break node specification. Returns:HardBreakSpecExtension
defineHardBreakCommands()
Defines hard break-related commands. Returns:HardBreakCommandsExtension
defineHardBreakKeymap()
Defines keyboard shortcuts for inserting hard breaks. Returns:PlainExtension
insertHardBreak()
Returns a command that inserts a hard break at the current selection. Returns:Command
Node Specification
The hard break node is defined with the following properties:- name:
hardBreak - inline:
true(exists within text content) - selectable:
false(cannot be selected) - group:
inline - leafText: Returns
\n(represents as newline in plain text) - parseDOM:
[{ tag: 'br' }] - toDOM: Renders as
<br>element
Commands
insertHardBreak()
Inserts a hard break (line break) at the current cursor position.Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Mod-Enter | Insert hard break |
Shift-Enter | Insert hard break |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
Examples
Basic Setup
Insert Button
Poetry or Addresses
Programmatic Insertion
Custom Behavior
Use Cases
Addresses
Poetry
Code Examples
Contact Information
Styling
Hard breaks render as standard<br> elements and don’t typically need styling:
HTML Structure
Input HTML:Behavior
vs. Paragraphs
Understand the difference between hard breaks and paragraphs:Plain Text Export
When converting to plain text, hard breaks become newline characters (\n):
Selection
Hard breaks are not selectable nodes (unlike horizontal rules). The cursor moves past them naturally as you navigate text.Accessibility
Hard breaks are semantic HTML:- Screen readers treat
<br>as a line break pause - Use for meaningful line breaks, not layout spacing
- Consider using CSS margins/padding for visual spacing instead
Common Patterns
Preventing Hard Breaks in Headings
Alternative: Shift+Enter Behavior
By default,Shift+Enter inserts a hard break. This is a common convention:
Enter→ New paragraphShift+Enter→ Line break within paragraph