Skip to content
gpdoc
Playground

Hard break

Insert a line break within a paragraph.

hard_break() adds an inline break. Use it for content such as an address that needs several lines within one paragraph.

Terminal window
cargo add gpdoc-plugin-hard-break

Register hard_break() with paragraph(). The inline hardBreak node takes no attributes.

Register the inline break alongside a paragraph that can contain it. Use this configuration in the Quickstart editor.

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

Type First, press Shift + Enter, and type Second. Both lines belong to the same paragraph.

use gpdoc::{DocPos, Editor, Node, Selection};
let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "FirstSecond")])?;
editor.select(Selection::caret(DocPos(6)))?;
editor.run(gpdoc_plugin_hard_break::Set)?;
assert_eq!(editor.document().blocks().len(), 1);
assert_eq!(editor.document().node_at(DocPos(6)).unwrap().kind, "hardBreak");

The first paragraph’s text starts at position 1. Its five-character prefix First puts the break at position 6.

Insert an inline break at the caret or replace selected text with a break. The text selection must be in content that accepts an inline break. The next line keeps the active typing marks, so a bold word can continue in bold after the break.

editor.run(gpdoc_plugin_hard_break::Set)?;
Shortcut Action
Shift + Enter Insert a hard break.
Mod + Enter Insert a hard break.

hard-break/src/lib.rs