# Highlight

> Mark text with a background color, with optional per-mark colors.

Highlight adds the `highlight` mark. Use it to call attention to a phrase while keeping the text color intact.

## Try it

[Try the highlight editor example](https://gpdoc.dev/docs/plugins/formatting/highlight/#highlight-example)

## Install

```sh
cargo add gpdoc-plugin-highlight
```

## Example

Set a fallback highlight color in the [Quickstart editor configuration](/docs/quickstart/#configure-the-editor).

```rust
use gpdoc::{EditorConfig, PluginViewExt};
use gpdoc_plugin_highlight::{highlight, highlight_format};
use gpdoc_plugin_paragraph::paragraph;


let config = EditorConfig::builder()
    .plugin(paragraph())
    .plugin(highlight().with_view(|| highlight_format([255, 232, 135])))
    .build()
    .expect("configure editor");
```

Type `==important==` to highlight the word with the yellow background set by the formatter.

Each highlight can store its own CSS color. The GPUI formatter uses its fallback color when the stored color is missing or invalid.

## Commands

At a caret, highlight commands change the formatting for subsequent typing. `editor.run` returns `Result<CommandOutcome, Error>`. Set and toggle return `NotApplicable` when the selection cannot take a highlight.

### `setHighlight`

Apply a highlight, or update the color of an existing one. Pass a CSS color string as shown, or pass `None` to use the configured fallback color.

```rust
editor.run(gpdoc_plugin_highlight::Set(Some("#ffa8a8".into())))?;
```

### `toggleHighlight`

Pass `None` to toggle highlighting regardless of color, or pass a specific color. The command removes the highlight if the whole eligible selection matches that color and otherwise applies it.

```rust
editor.run(gpdoc_plugin_highlight::Toggle(None))?;
```

### `unsetHighlight`

Remove the highlight regardless of its color.

```rust
editor.run(gpdoc_plugin_highlight::Unset)?;
```

## Keyboard shortcuts

Toggle highlighting with **Command + Shift + H** on macOS or **Ctrl + Shift + H** on Windows and Linux.

Typing `==important==` highlights the word between the delimiters.