Skip to content
gpdoc
Playground

Paragraph

Add the default text block to an editor.

paragraph() registers the text block most documents start with. A paragraph can contain text, marks, and inline nodes such as mentions, depending on the rest of your schema.

Terminal window
cargo add gpdoc-plugin-paragraph

Register paragraph() in your editor configuration. This makes paragraph the default text block. It has no attributes and accepts zero or more inline children.

Register the paragraph as the default text block. Use this configuration in the Quickstart editor.

use gpdoc::{EditorConfig, PluginViewExt, ViewPlugin};
use gpdoc_plugin_paragraph::{paragraph, paragraph_block};
let config = EditorConfig::builder()
.plugin(paragraph().with_view(paragraph_view))
.build()
.expect("configure editor");
fn paragraph_view() -> ViewPlugin {
paragraph_block(|block, _, _| block.content)
}

Type a few words, press Enter, and continue typing in a second paragraph.

The editor supplies the paragraph contents as a single element. Place that element once in your own wrapper.

paragraph_block(...)
└── div() Your wrapper
└── block.content Editable text, marks, and inline nodes

Replace paragraph_view in the example above.

use gpui::{div, prelude::*};
fn paragraph_view() -> ViewPlugin {
paragraph_block(|block, _, _| {
div().child(block.content)
})
}

With the configuration above, open a document with an initial paragraph.

use gpdoc::{Editor, Node};
let block = Node::textblock("paragraph", "Write here.");
let mut editor = Editor::from_document(&config, vec![block.clone()])?;
assert_eq!(editor.document().blocks(), &[block]);

For an empty editor, pass Node::textblock("paragraph", "") as the first block.

Convert the text block at the caret, or selected text blocks, to body text wherever their parent permits a paragraph. The conversion keeps supported inline content and marks. A gap selection supplies no blocks to convert.

editor.run(gpdoc_plugin_paragraph::Set)?;
Shortcut Action
Mod + Alt + 0 Convert selected text blocks to paragraphs.

paragraph/src/lib.rs