# 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.

## Try it

[Try the horizontal-rule editor example](https://gpdoc.dev/docs/plugins/structure/horizontal-rule/#horizontal-rule-example)

## Install

```sh
cargo add gpdoc-plugin-horizontal-rule
```

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

## Example

Register a paragraph alongside the divider so the caret has a place to continue typing. Use this configuration in the [Quickstart editor](/docs/quickstart/#configure-the-editor).

```rust
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.

## Insert a divider before a paragraph

```rust
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);
```

## Commands

### `setHorizontalRule`

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.

```rust
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.

## Insert a divider while typing

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.

## Source code

[horizontal-rule/src/lib.rs](/source/plugins/horizontal-rule/src/lib.rs.txt)