Skip to content
gpdoc
Playground

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.

Terminal window
cargo add gpdoc-plugin-highlight

Set a fallback highlight color in the Quickstart editor configuration.

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.

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.

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.

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

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.

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

Remove the highlight regardless of its color.

editor.run(gpdoc_plugin_highlight::Unset)?;

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

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