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.
Try it
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-ordered-list gpdoc-plugin-list-itemExample
Section titled “Example”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.
Compose a numbered list
Section titled “Compose a numbered list”Wrap the whole list with ordered_list_body. The list item view supplies each number from the starting counter and the item’s index.
Anatomy
Section titled “Anatomy”ordered_list_body(...)└── div() Your wrapper └── block.content Editable items with their decimal markersWrap the numbered items
Section titled “Wrap the numbered items”Replace numbered_view in the example above.
use gpui::{div, prelude::*};
fn numbered_view() -> ViewPlugin { ordered_list_body(|block, _, _| { div().child(block.content) })}Start numbering at four
Section titled “Start numbering at four”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));Settings
Section titled “Settings”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.
Commands
Section titled “Commands”toggleOrderedList
Section titled “toggleOrderedList”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() })?;wrapInOrderedList
Section titled “wrapInOrderedList”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())?;Keyboard shortcuts
Section titled “Keyboard shortcuts”| 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.