# 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

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

## Install

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

## Example

Register the paragraph as the default text block. Use this configuration in the [Quickstart editor](/docs/quickstart/#configure-the-editor).

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

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

### Anatomy

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

### Wrap the editable paragraph

Replace `paragraph_view` in the example above.

```rust
use gpui::{div, prelude::*};


fn paragraph_view() -> ViewPlugin {
    paragraph_block(|block, _, _| {
        div().child(block.content)
    })
}
```

## Open a document with one paragraph

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

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

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

```rust
editor.run(gpdoc_plugin_paragraph::Set)?;
```

## Keyboard shortcuts

| Shortcut          | Action                                      |
| ----------------- | ------------------------------------------- |
| **Mod + Alt + 0** | Convert selected text blocks to paragraphs. |

## Source code

[paragraph/src/lib.rs](/source/plugins/paragraph/src/lib.rs.txt)