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.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-paragraphRegister paragraph() in your editor configuration. This makes paragraph the default text block. It has no attributes and accepts zero or more inline children.
Example
Section titled “Example”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.
Compose a paragraph
Section titled “Compose a paragraph”The editor supplies the paragraph contents as a single element. Place that element once in your own wrapper.
Anatomy
Section titled “Anatomy”paragraph_block(...)└── div() Your wrapper └── block.content Editable text, marks, and inline nodesWrap the editable paragraph
Section titled “Wrap the editable paragraph”Replace paragraph_view in the example above.
use gpui::{div, prelude::*};
fn paragraph_view() -> ViewPlugin { paragraph_block(|block, _, _| { div().child(block.content) })}Open a document with one paragraph
Section titled “Open a document with one paragraph”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.
Commands
Section titled “Commands”setParagraph
Section titled “setParagraph”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)?;Keyboard shortcuts
Section titled “Keyboard shortcuts”| Shortcut | Action |
|---|---|
| Mod + Alt + 0 | Convert selected text blocks to paragraphs. |