Overview
Thehorizontal-rule extension adds support for horizontal rule nodes, which create visual dividers between sections of content. These render as <hr> elements.
Installation
Usage
API Reference
defineHorizontalRule()
Defines a horizontal rule node with commands, input rules, and node specification. Returns:HorizontalRuleExtension
This extension includes:
- Node specification
- Insert command
- Input rules for Markdown-style syntax
defineHorizontalRuleSpec()
Defines only the horizontal rule node specification. Returns:HorizontalRuleSpecExtension
defineHorizontalRuleCommands()
Defines horizontal rule-related commands. Returns:HorizontalRuleCommandsExtension
defineHorizontalRuleInputRule()
Defines input rules for Markdown-style horizontal rule syntax. Returns:PlainExtension
insertHorizontalRule()
Returns a command that inserts a horizontal rule at the current selection. Returns:Command
Node Specification
The horizontal rule node is defined with the following properties:- name:
horizontalRule - group:
block - parseDOM:
[{ tag: 'hr' }] - toDOM: Renders as
<div class="prosekit-horizontal-rule"><hr></div>
<hr> is wrapped in a <div> to make it taller and easier to click in the editor.
Commands
insertHorizontalRule()
Inserts a horizontal rule at the current cursor position.Input Rules
The extension supports Markdown-style horizontal rule syntax:---) on an empty line to insert a horizontal rule.
Examples
Basic Setup
Insert Button
Toolbar Integration
Programmatic Insertion
Using the Direct Command
Styling
Horizontal rules are wrapped in a div for better editor interaction:Minimal Styling
Custom Styles
HTML Structure
Input HTML:Use Cases
- Separating sections in long documents
- Creating visual breaks between topics
- Dividing content chapters
- Adding structure to articles
- Marking thematic breaks in content
Behavior
Selection
Horizontal rules are selectable nodes. Click on them to select, then:- Press
DeleteorBackspaceto remove - Use arrow keys to navigate past them
Insertion
Horizontal rules are inserted at the current cursor position and create their own block:Accessibility
Horizontal rules are semantic HTML elements:- Represent a thematic break in content
- Screen readers announce them as separators
- Should be used for meaningful content separation, not just visual styling