Overview
Theheading extension adds support for heading nodes with levels 1-6, corresponding to HTML <h1> through <h6> elements. Headings are essential for document structure and hierarchy.
Installation
Usage
API Reference
defineHeading()
Defines a heading node with commands, keymap, input rules, and node specification. Returns:HeadingExtension
This extension includes:
- Node specification with level attribute
- Commands for manipulating headings
- Keyboard shortcuts for levels 1-6
- Input rules for Markdown-style syntax
defineHeadingSpec()
Defines only the heading node specification. Returns:HeadingSpecExtension
defineHeadingCommands()
Defines heading-related commands. Returns:HeadingCommandsExtension
defineHeadingKeymap()
Defines keyboard shortcuts for heading operations. Returns:PlainExtension
defineHeadingInputRule()
Defines input rules for Markdown-style heading syntax. Returns:PlainExtension
Node Specification
The heading node is defined with the following properties:- name:
heading - content:
inline*(accepts zero or more inline nodes) - group:
block - defining:
true(prevents wrapping) - attrs:
level: number (1-6, default: 1)
- parseDOM: Parses
<h1>through<h6>tags - toDOM: Renders as appropriate
<h1>-<h6>element based on level
Types
HeadingAttrs
Commands
setHeading(attrs?)
Converts the current block to a heading. Parameters:attrs?: HeadingAttrs- Optional attributes. If omitted, defaults to level 1.
insertHeading(attrs?)
Inserts a new heading node. Parameters:attrs?: HeadingAttrs- Optional attributes. If omitted, defaults to level 1.
toggleHeading(attrs?)
Toggles between a heading and paragraph. Parameters:attrs?: HeadingAttrs- Optional attributes. If omitted, defaults to level 1.
Keyboard Shortcuts
| Shortcut | Action |
|---|---|
Mod-Alt-1 | Toggle heading level 1 |
Mod-Alt-2 | Toggle heading level 2 |
Mod-Alt-3 | Toggle heading level 3 |
Mod-Alt-4 | Toggle heading level 4 |
Mod-Alt-5 | Toggle heading level 5 |
Mod-Alt-6 | Toggle heading level 6 |
Backspace | Convert to paragraph when at start of heading |
Mod is Cmd on macOS and Ctrl on Windows/Linux.
Input Rules
The extension supports Markdown-style heading syntax:Examples
Basic Setup
Heading Toolbar
Dropdown Selector
Check Active Heading Level
Styling
Heading nodes render as standard HTML heading elements:HTML Structure
Input HTML:Accessibility
Headings are crucial for document accessibility:- Use headings to create a logical document outline
- Don’t skip heading levels (e.g., don’t go from h1 to h3)
- Use only one h1 per page for the main title
- Screen readers use headings for navigation
Related Extensions
- Paragraph - Default block type
- Text - Required for text content within headings
- Blockquote - For quoted content