Overview
Theparagraph extension adds support for paragraph nodes, which are the default block-level containers for inline content. Paragraphs are typically the most commonly used block type in rich text editors.
Installation
Usage
API Reference
defineParagraph()
Defines a paragraph node with commands, keymap, and node specification. This is the main function you’ll use to add paragraph support. Returns:ParagraphExtension
This extension includes:
- Node specification
- Commands for manipulating paragraphs
- Keyboard shortcuts
defineParagraphSpec()
Defines only the paragraph node specification without commands or keymaps. Returns:ParagraphSpecExtension
defineParagraphCommands()
Defines paragraph-related commands. Returns:ParagraphCommandsExtension
defineParagraphKeymap()
Defines keyboard shortcuts for paragraph operations. Returns:PlainExtension
Node Specification
The paragraph node is defined with the following properties:- name:
paragraph - content:
inline*(accepts zero or more inline nodes) - group:
block - parseDOM:
[{ tag: 'p' }] - toDOM: Renders as
<p>element - priority:
4(highest) - paragraphs are the default block node
Commands
setParagraph()
Converts the current block to a paragraph.Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Mod-Alt-0 | Convert current block to paragraph |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
Examples
Basic Setup
Programmatically Setting Paragraphs
Custom Paragraph Button
Reset to Paragraph After Heading
Styling
Paragraph nodes render as standard<p> HTML elements. You can style them with CSS:
HTML Structure
Input HTML:Related Extensions
- Text - Required for text content within paragraphs
- Heading - Alternative block type for titles
- Blockquote - For quoted text blocks
- Code Block - For code snippets