Plugins
Browse gpdoc plugins by feature and find install commands and Rust examples.
Choose a plugin to see how to register it in the Quickstart editor. For plugins with UI components, the Compose section shows how to assemble their parts in your own view.
Formatting
- BoldMark selected text or the next typed characters as bold.
- HighlightMark text with a background color, with optional per-mark colors.
- Inline codeDisplay a code fragment in a line of text with a monospace font.
- ItalicMark selected text or the next typed characters as italic.
- LinkAdd links to selected text or detect addresses as users type and paste.
- Ruby textAttach a pronunciation guide to text such as Japanese kanji.
- StrikethroughDraw a line through text that readers can still see.
- SubscriptDisplay selected characters below the text baseline.
- SuperscriptDisplay selected characters above the text baseline.
- Text alignmentAlign paragraphs, headings, or other configured blocks.
- Text styleSet text color, background color, font family, font size, or line height.
- UnderlineDraw a line beneath selected text or the next typed characters.
Blocks
- BlockquoteWrap one or more selected blocks in a quote.
- Code blockStore multiline code with an optional language.
- ColumnsArrange blocks in two or more editable columns, drag blocks between them, and resize adjacent columns.
- DetailsWrap blocks in a disclosure with an editable summary.
- Hard breakInsert a line break within a paragraph.
- HeadingTurn text blocks into headings with levels 1 through 6.
- Horizontal ruleAdd a divider between sections of a document.
- ParagraphAdd the default text block to an editor.
- Trailing nodeKeep an editable block at the end of a document after edits.
- Unique IDAssign stable IDs to selected node types when a document opens or changes.
Lists and tables
- Bullet listTurn paragraphs into an unordered list.
- List itemAdd the shared item type for bullet and ordered lists.
- List keyboard shortcutsHandle Backspace, Delete, and Tab at list boundaries.
- Ordered listTurn paragraphs into a numbered list and set its starting number.
- TableInsert tables and edit their rows, columns, headers, and cells.
- Task listCreate checklists with a saved checked state for each item.
Media and math
Menus
- Bubble menuShow a contextual menu above a selection.
- Floating menuShow a menu at the caret in an empty top-level paragraph.
- MentionInsert a reference to a person or other named item.
- Slash commandChoose a block command by typing a slash at the start of a top-level paragraph.
- SuggestionFind a completion query before the caret and replace it with an inline node.
Selection
- Box selectionDrag a rectangle from the margin outside a block to select whole blocks.
- Drag handleConfigure the gutter width, grip height, grip renderer, and drag preview.
- Drop cursorDraw an insertion indicator while dragging over the editor.
- FocusHighlight the block containing the selection anchor while the editor has focus.
- Gap cursorPlace the caret between closed blocks in a GPUI editor.
- Node rangeSelect whole sibling blocks with the keyboard or a modifier drag.
Writing tools
- Character countCount characters and words or enforce a character limit.
- Find and replaceHighlight, navigate, and replace matching text in a document.
- Invisible charactersDisplay markers for spaces, line breaks, and paragraph ends.
- PlaceholderShow a writing hint in an empty text block.
- Table of contentsAssign heading anchors and read an outline for document navigation.
- TypographyTurn typed punctuation and symbols into typographic characters.
Files and Markdown
Collaboration
Try a different name or keyword.
Register a plugin
Section titled “Register a plugin”Register plugins before opening a document. Use gpdoc::EditorConfig::builder() to register plugins, then pass the configuration to an editor constructor. A plugin can define a node, a mark, a command, a shortcut, or a rule that runs as you type. The engine provides the doc and text types. Add Paragraph for the default text block.
If a snippet uses an existing editor, register the required plugins in an EditorConfig and place the snippet inside main after creating the editor. For examples that call a codec or collaboration API, use Result<(), Box<dyn std::error::Error>> as the return type of main.
Register GPUI views
Section titled “Register GPUI views”In the Quickstart app, add Placeholder and Gap cursor. Register each plugin to use its default GPUI behavior.
cargo add gpdoc-plugin-placeholder gpdoc-plugin-gap-cursoruse gpdoc_plugin_gap_cursor::gap_cursor;use gpdoc_plugin_paragraph::paragraph;use gpdoc_plugin_placeholder::placeholder;
let config = gpdoc::EditorConfig::builder() .plugin(paragraph()) .plugin(placeholder("Write an update…")) .plugin(gap_cursor()) .build()?;An empty paragraph shows the writing hint. In a document with adjacent closed blocks, click their boundary to place the gap cursor. To change how a plugin looks, define a view in your application and register it with .with_view(...).
For an editable block, wrap the paragraph content in a GPUI element. For a menu, compose a slash command picker with your own panel and rows. To put an action above the caret, add a button to a link popover.
Format a selection
Section titled “Format a selection”From your Quickstart project, add the two formatting plugins.
cargo add gpdoc-plugin-bold gpdoc-plugin-italicReplace src/main.rs with this example and run cargo run. The program prints the marks attached to release notes.
use gpdoc::{DocPos, Editor, EditorConfig, Error, Node, Selection};use gpdoc_plugin_bold::bold;use gpdoc_plugin_italic::italic;use gpdoc_plugin_paragraph::paragraph;
fn main() -> Result<(), Error> { let config = EditorConfig::builder() .plugin(paragraph()) .plugin(bold()) .plugin(italic()) .build()?; let mut editor = Editor::from_document(&config, vec![Node::textblock( "paragraph", "Give the release notes a little emphasis.", )])?;
editor.select(Selection::Text { anchor: DocPos(10), head: DocPos(23), })?; editor.run(gpdoc_plugin_bold::Toggle)?; editor.run(gpdoc_plugin_italic::Toggle)?;
let (_, phrase) = editor .document() .iter_nodes() .find(|(_, node)| node.projected_text() == "release notes") .expect("the selected phrase has its own text node"); for mark in phrase.marks() { println!("{}", mark.kind); } Ok(())}bolditalicCommands
Section titled “Commands”Pass a command value exported by the plugin to editor.run(command). Its Rust type specifies the arguments.
Result from editor.run |
Meaning |
|---|---|
Ok(CommandOutcome::Applied(change)) |
The editor applied the command’s transaction and returned an AppliedChange. |
Ok(CommandOutcome::NotApplicable) |
The command declined the current selection or arguments. The editor stays as it was. |
Ok(CommandOutcome::Rejected) |
A transaction filter declined the final draft. The document and undo history are unchanged. GPUI consumes the shortcut. |
Err(Error::UnknownCommand(name)) |
Register the plugin that handles this command type. |
Other Err(error) |
Planning or applying the transaction failed. The error describes the cause. |
When wiring a toolbar button, pass its command value to editor.can(command). It returns Ok(true) when the handler can plan a valid transaction in the current context. The editor discards that transaction. On click, run() plans again, runs append hooks, and lets filters accept or reject the final draft. A button can therefore be enabled and its command still return Rejected.
The editor has built-in local undo and redo. Use editor.undo() and editor.redo() to move through the history.
Build a plugin
Section titled “Build a plugin”Create your first plugin to build and test a caption block. Then choose a guide for the feature you want to add.
| To add | Guide |
|---|---|
| A document type, a formatting mark, or a validated field | Nodes, marks, and attributes |
| An editing action with a keyboard binding | Commands and shortcuts |
| A value that an editor remembers between commands | Transactions and plugin state |
| A conversion triggered by typing or pasting | Input and paste rules |
| A native renderer for an editable block | Render a plugin in GPUI |
For signatures and hook behavior, see the Plugin API reference.