Skip to content
gpdoc
Playground

Horizontal rule

Add a divider between sections of a document.

horizontal_rule() adds a divider as a standalone block. Use it to separate two sections without adding a heading.

Terminal window
cargo add gpdoc-plugin-horizontal-rule

In a GPUI editor, the default view draws the divider.

Register a paragraph alongside the divider so the caret has a place to continue typing. Use this configuration in the Quickstart editor.

use gpdoc::EditorConfig;
use gpdoc_plugin_paragraph::paragraph;
use gpdoc_plugin_horizontal_rule::horizontal_rule;
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(horizontal_rule())
.build()
.expect("configure editor");

At the start of a paragraph, type ---. The editor inserts the divider and puts the caret in a paragraph.

use gpdoc::{Editor, Node};
let next_section = Node::textblock("paragraph", "Next section");
let mut editor = Editor::from_document(&config, vec![next_section.clone()])?;
editor.run(gpdoc_plugin_horizontal_rule::Set)?;
let blocks = editor.document().blocks();
assert_eq!(blocks[0].kind, "horizontalRule");
assert_eq!(blocks[1], next_section);

Insert a divider where the schema permits one. At the start of a nonempty paragraph, it goes before the paragraph. In the middle, it splits the paragraph. A text range replaces the selected content, a gap selection inserts at the gap, and a node selection inserts after the node.

editor.run(gpdoc_plugin_horizontal_rule::Set)?;

When the next sibling is a text block, the caret moves to its start. At the end of the document, the command creates a default text block after the divider if the parent permits it.

Start a text block with ---. The third hyphen triggers the rule and consumes the marker. You can also type ___ or *** followed by a space. Inside code blocks, these markers remain literal punctuation.

horizontal-rule/src/lib.rs