Skip to content
gpdoc
Playground

Ordered list

Turn paragraphs into a numbered list and set its starting number.

ordered_list() wraps paragraphs in a numbered list. Its start attribute controls the number of the first item.

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

Register the numbered list and its item type. 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_ordered_list::{ordered_list, ordered_list_body};
let config = EditorConfig::builder()
.plugin(paragraph())
.plugin(list_item())
.plugin(ordered_list().with_view(numbered_view))
.build()
.expect("configure editor");
fn numbered_view() -> ViewPlugin {
ordered_list_body(|block, _, _| block.content)
}

Type 1. followed by a space at the start of a paragraph. The editor creates a numbered item.

Wrap the whole list with ordered_list_body. The list item view supplies each number from the starting counter and the item’s index.

ordered_list_body(...)
└── div() Your wrapper
└── block.content Editable items with their decimal markers

Replace numbered_view in the example above.

use gpui::{div, prelude::*};
fn numbered_view() -> ViewPlugin {
ordered_list_body(|block, _, _| {
div().child(block.content)
})
}
use gpdoc::{Editor, Node, Value};
let mut editor = Editor::from_document(&config, vec![Node::textblock("paragraph", "Publish the release")])?;
editor.run(gpdoc_plugin_ordered_list::Toggle { start: Some(4), ..Default::default() })?;
assert_eq!(editor.document().blocks()[0].attrs["start"], Value::from(4));

Register gpdoc_plugin_ordered_list::ordered_list() with paragraph() and list_item(). Pass the following attributes when creating a list.

The first number in the list. Defaults to integer 1. Pass 4 to label the first two items 4 and 5.

Optional string on the list node, default null. The typed-marker rule continues a preceding list when its type is null or "1" and the typed number is next in sequence.

Wrap the current or selected paragraphs. Inside an ordered list, lift the selected items. Inside a compatible list of another type, convert it to an ordered list.

editor.run(gpdoc_plugin_ordered_list::Toggle { start: Some(4), ..Default::default() })?;

Wrap each selected paragraph in a list item. A preceding ordered list absorbs the new items and supplies their numbering.

editor.run(gpdoc_plugin_ordered_list::Wrap::default())?;
Shortcut Command
Mod + Shift + 7 toggleOrderedList

At the start of a paragraph, type a number, a period, and a space. After a list containing items 4 and 5, typing 6. followed by a space continues that list. Typing 1. followed by a space starts a separate list.

ordered-list/src/lib.rs