# 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](/docs/quickstart/#configure-the-editor). For plugins with UI components, the Compose section shows how to assemble their parts in your own view.

Find a pluginSearch by name, crate, or use

## Formatting

* [BoldMark selected text or the next typed characters as bold.](/docs/plugins/formatting/bold/)
* [HighlightMark text with a background color, with optional per-mark colors.](/docs/plugins/formatting/highlight/)
* [Inline codeDisplay a code fragment in a line of text with a monospace font.](/docs/plugins/formatting/inline-code/)
* [ItalicMark selected text or the next typed characters as italic.](/docs/plugins/formatting/italic/)
* [LinkAdd links to selected text or detect addresses as users type and paste.](/docs/plugins/formatting/link/)
* [Ruby textAttach a pronunciation guide to text such as Japanese kanji.](/docs/plugins/formatting/ruby-text/)
* [StrikethroughDraw a line through text that readers can still see.](/docs/plugins/formatting/strike/)
* [SubscriptDisplay selected characters below the text baseline.](/docs/plugins/formatting/subscript/)
* [SuperscriptDisplay selected characters above the text baseline.](/docs/plugins/formatting/superscript/)
* [Text alignmentAlign paragraphs, headings, or other configured blocks.](/docs/plugins/formatting/text-align/)
* [Text styleSet text color, background color, font family, font size, or line height.](/docs/plugins/formatting/text-style/)
* [UnderlineDraw a line beneath selected text or the next typed characters.](/docs/plugins/formatting/underline/)

## Blocks

* [BlockquoteWrap one or more selected blocks in a quote.](/docs/plugins/structure/blockquote/)
* [Code blockStore multiline code with an optional language.](/docs/plugins/structure/code-block/)
* [ColumnsArrange blocks in two or more editable columns, drag blocks between them, and resize adjacent columns.](/docs/plugins/structure/columns/)
* [DetailsWrap blocks in a disclosure with an editable summary.](/docs/plugins/structure/details/)
* [Hard breakInsert a line break within a paragraph.](/docs/plugins/structure/hard-break/)
* [HeadingTurn text blocks into headings with levels 1 through 6.](/docs/plugins/structure/heading/)
* [Horizontal ruleAdd a divider between sections of a document.](/docs/plugins/structure/horizontal-rule/)
* [ParagraphAdd the default text block to an editor.](/docs/plugins/structure/paragraph/)
* [Trailing nodeKeep an editable block at the end of a document after edits.](/docs/plugins/behavior/trailing-node/)
* [Unique IDAssign stable IDs to selected node types when a document opens or changes.](/docs/plugins/behavior/unique-id/)

## Lists and tables

* [Bullet listTurn paragraphs into an unordered list.](/docs/plugins/structure/bullet-list/)
* [List itemAdd the shared item type for bullet and ordered lists.](/docs/plugins/structure/list-item/)
* [List keyboard shortcutsHandle Backspace, Delete, and Tab at list boundaries.](/docs/plugins/structure/list-keymap/)
* [Ordered listTurn paragraphs into a numbered list and set its starting number.](/docs/plugins/structure/ordered-list/)
* [TableInsert tables and edit their rows, columns, headers, and cells.](/docs/plugins/structure/table/)
* [Task listCreate checklists with a saved checked state for each item.](/docs/plugins/structure/task-list/)

## Media and math

* [AudioStore an audio source and playback attributes in the document.](/docs/plugins/media/audio/)
* [ImageInsert an image with alternative text and optional dimensions.](/docs/plugins/media/image/)
* [MathematicsInsert inline or standalone LaTeX formulas.](/docs/plugins/media/mathematics/)

## Menus

* [Bubble menuShow a contextual menu above a selection.](/docs/plugins/behavior/bubble-menu/)
* [Floating menuShow a menu at the caret in an empty top-level paragraph.](/docs/plugins/behavior/floating-menu/)
* [MentionInsert a reference to a person or other named item.](/docs/plugins/media/mention/)
* [Slash commandChoose a block command by typing a slash at the start of a top-level paragraph.](/docs/plugins/behavior/slash-command/)
* [SuggestionFind a completion query before the caret and replace it with an inline node.](/docs/plugins/behavior/suggestion/)

## Selection

* [Box selectionDrag a rectangle from the margin outside a block to select whole blocks.](/docs/plugins/behavior/box-selection/)
* [Drag handleConfigure the gutter width, grip height, grip renderer, and drag preview.](/docs/plugins/behavior/drag-handle/)
* [Drop cursorDraw an insertion indicator while dragging over the editor.](/docs/plugins/behavior/drop-cursor/)
* [FocusHighlight the block containing the selection anchor while the editor has focus.](/docs/plugins/behavior/focus/)
* [Gap cursorPlace the caret between closed blocks in a GPUI editor.](/docs/plugins/behavior/gap-cursor/)
* [Node rangeSelect whole sibling blocks with the keyboard or a modifier drag.](/docs/plugins/behavior/node-range/)

## Writing tools

* [Character countCount characters and words or enforce a character limit.](/docs/plugins/behavior/character-count/)
* [Find and replaceHighlight, navigate, and replace matching text in a document.](/docs/plugins/behavior/find-and-replace/)
* [Invisible charactersDisplay markers for spaces, line breaks, and paragraph ends.](/docs/plugins/behavior/invisible-characters/)
* [PlaceholderShow a writing hint in an empty text block.](/docs/plugins/behavior/placeholder/)
* [Table of contentsAssign heading anchors and read an outline for document navigation.](/docs/plugins/behavior/table-of-contents/)
* [TypographyTurn typed punctuation and symbols into typographic characters.](/docs/plugins/behavior/typography/)

## Files and Markdown

* [File handlerReceive dropped paths and pasted clipboard images in your GPUI app.](/docs/plugins/behavior/file-handler/)
* [MarkdownImport CommonMark into a gpdoc editor and export it back to Markdown.](/docs/plugins/behavior/markdown/)

## Collaboration

* [CollaborationSynchronize editor documents by exchanging Yjs-compatible updates.](/docs/plugins/collaboration/collaboration/)
* [Collaboration caretExchange presence updates and track remote carets and selections.](/docs/plugins/collaboration/collaboration-caret/)

Try a different name or keyword.

## 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](/docs/plugins/structure/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

In the [Quickstart app](/docs/quickstart/#configure-the-editor), add [Placeholder](/docs/plugins/behavior/placeholder/) and [Gap cursor](/docs/plugins/behavior/gap-cursor/). Register each plugin to use its default GPUI behavior.

```sh
cargo add gpdoc-plugin-placeholder gpdoc-plugin-gap-cursor
```

```rust
use 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](/docs/quickstart/#style-a-paragraph). For a menu, [compose a slash command picker](/docs/plugins/behavior/slash-command/#compose-a-slash-menu) with your own panel and rows. To put an action above the caret, [add a button to a link popover](/docs/plugins/formatting/link/#compose-a-link-popover).

## Format a selection

[Format a selection](https://gpdoc.dev/docs/plugins/#format-example)

From your [Quickstart project](/docs/quickstart/), add the two formatting plugins.

```sh
cargo add gpdoc-plugin-bold gpdoc-plugin-italic
```

Replace `src/main.rs` with this example and run `cargo run`. The program prints the marks attached to `release notes`.

```rust
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(())
}
```

```text
bold
italic
```

## 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

[Create your first plugin](/docs/plugins/custom/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](/docs/plugins/custom/schema/)   |
| An editing action with a keyboard binding                | [Commands and shortcuts](/docs/plugins/custom/commands/)       |
| A value that an editor remembers between commands        | [Transactions and plugin state](/docs/plugins/custom/state/)   |
| A conversion triggered by typing or pasting              | [Input and paste rules](/docs/plugins/custom/input-and-paste/) |
| A native renderer for an editable block                  | [Render a plugin in GPUI](/docs/plugins/custom/gpui/)          |

For signatures and hook behavior, see the [Plugin API reference](/docs/plugins/custom/api/).