Skip to content
gpdoc
Playground

Bullet list

Turn paragraphs into an unordered list.

bullet_list() wraps paragraphs in a list with bullet markers. It uses the shared List item plugin for each entry.

Terminal window
cargo add gpdoc-plugin-bullet-list gpdoc-plugin-list-item

Register the list container and the item type it accepts. Use this configuration in the Quickstart editor.

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.

Wrap the whole list with bullet_list_body. The list item view supplies each bullet and its editable body.

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

Replace bullets_view in the example above.

use gpui::{div, prelude::*};
fn bullets_view() -> ViewPlugin {
bullet_list_body(|block, _, _| {
div().child(block.content)
})
}
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");

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.

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.

editor.run(gpdoc_plugin_bullet_list::Toggle)?;

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

editor.run(gpdoc_plugin_bullet_list::Wrap)?;
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.

bullet-list/src/lib.rs