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
Section titled “Try it”Install
Section titled “Install”cargo add gpdoc-plugin-highlightExample
Section titled “Example”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.
Commands
Section titled “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
Section titled “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.
editor.run(gpdoc_plugin_highlight::Set(Some("#ffa8a8".into())))?;toggleHighlight
Section titled “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.
editor.run(gpdoc_plugin_highlight::Toggle(None))?;unsetHighlight
Section titled “unsetHighlight”Remove the highlight regardless of its color.
editor.run(gpdoc_plugin_highlight::Unset)?;Keyboard shortcuts
Section titled “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.