# Blockquote

> Wrap one or more selected blocks in a quote.

`blockquote()` wraps one or more blocks in a quote. The wrapped blocks keep their text and structure.

## Try it

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

## Install

```sh
cargo add gpdoc-plugin-blockquote
```

## Example

Register the quote alongside the paragraph it can wrap. Use this configuration in the [Quickstart editor](/docs/quickstart/#configure-the-editor).

```rust
use gpdoc::{EditorConfig, PluginViewExt, ViewPlugin};
use gpdoc_plugin_paragraph::paragraph;
use gpdoc_plugin_blockquote::{blockquote, quote_block};


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(blockquote().with_view(quote_view))
    .build()
    .expect("configure editor");


fn quote_view() -> ViewPlugin {
    quote_block(|block, _, _| block.content)
}
```

At the start of a paragraph, type `>` followed by a space. The paragraph becomes the first block in the quote.

## Compose a blockquote

Place the quoted blocks inside one wrapper. Nested paragraphs and lists keep their block views.

### Anatomy

```text
quote_block(...)
└── div()              Your wrapper
    └── block.content  Editable paragraphs, lists, and nested quotes
```

### Wrap the quoted blocks

Replace `quote_view` in the example above.

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


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

## Wrap a paragraph

```rust
use gpdoc::{Editor, Node};


let paragraph = Node::textblock("paragraph", "The launch is on Friday.");
let mut editor = Editor::from_document(&config, vec![paragraph.clone()])?;


editor.run(gpdoc_plugin_blockquote::Set)?;
assert_eq!(editor.document().blocks()[0].kind, "blockquote");


editor.run(gpdoc_plugin_blockquote::Unset)?;
assert_eq!(editor.document().blocks(), &[paragraph]);
```

## Commands

### `setBlockquote`

Wrap the selected sibling blocks in a single quote. A caret targets its paragraph. A selection spanning parts of two paragraphs includes both whole paragraphs. A gap selection supplies no blocks to wrap.

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

### `unsetBlockquote`

Remove the nearest quote that contains the entire selection. Its child blocks remain in order.

```rust
editor.run(gpdoc_plugin_blockquote::Unset)?;
```

### `toggleBlockquote`

Unwrap an enclosing quote when possible. Otherwise, wrap the selected blocks. Use this command for a single **Quote** button.

```rust
editor.run(gpdoc_plugin_blockquote::Toggle)?;
```

## Keyboard shortcuts

| Shortcut            | Action                                 |
| ------------------- | -------------------------------------- |
| **Mod + Shift + B** | Toggle the quote around the selection. |

## Start a quote while typing

Type `>` followed by a space at the start of a paragraph. The editor removes the marker and wraps the paragraph.

## Source code

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