# Bullet list

> Turn paragraphs into an unordered list.

`bullet_list()` wraps paragraphs in a list with bullet markers. It uses the shared [List item](/docs/plugins/structure/list-item/) plugin for each entry.

## Try it

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

## Install

```sh
cargo add gpdoc-plugin-bullet-list gpdoc-plugin-list-item
```

## Example

Register the list container and the item type it accepts. 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_list_item::list_item;
use gpdoc_plugin_bullet_list::{bullet_list, bullet_list_body};


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(list_item())
    .plugin(bullet_list().with_view(bullets_view))
    .build()
    .expect("configure editor");


fn bullets_view() -> ViewPlugin {
    bullet_list_body(|block, _, _| block.content)
}
```

Type `-` followed by a space to start a bullet list.

## Compose a bullet list

Wrap the whole list with `bullet_list_body`. The [list item view](/docs/plugins/structure/list-item/#compose-a-list-item) supplies each bullet and its editable body.

### Anatomy

```text
bullet_list_body(...)
└── div()              Your wrapper
    └── block.content  Editable items with their bullet markers
```

### Wrap the list items

Replace `bullets_view` in the example above.

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


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

## Wrap a paragraph in a bullet list

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


let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "Keep a changelog")])?;
editor.run(gpdoc_plugin_bullet_list::Toggle)?;


assert_eq!(editor.document().blocks()[0].kind, "bulletList");
```

## Settings

`gpdoc_plugin_bullet_list::bullet_list()` takes no options. Register it with `paragraph()` and `list_item()`. A `bulletList` has no attributes and contains one or more `listItem` nodes.

## Commands

### `toggleBulletList`

With a caret in a paragraph, make it a bullet. Select across paragraphs to create several items. Toggling inside a top-level bullet list lifts the selected items back into paragraphs. Inside a compatible list of another type, the command converts the list to bullets.

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

### `wrapInBulletList`

Wrap the selected paragraphs in one list, preserving their text and inline marks. Adjacent bullet lists join the new items.

```rust
editor.run(gpdoc_plugin_bullet_list::Wrap)?;
```

## Keyboard shortcuts

| Shortcut            | Command            |
| ------------------- | ------------------ |
| **Mod + Shift + 8** | `toggleBulletList` |

At the start of a paragraph, type `-`, `+`, or `*` followed by a space. The input rule replaces the marker with a bullet.

## Source code

[bullet-list/src/lib.rs](/source/plugins/bullet-list/src/lib.rs.txt)