highlightText

Utility function to highlight matching text portions in search results

Installation

Overview

highlightText wraps matching portions of text in styled <mark> elements, making it easy to show users which parts of a result match their search query.

Usage

Example with Command

API Reference

Parameters

Prop

Returns

ReactNode - The original text with matched portions wrapped in styled <mark> elements.

Styling

Matched text is wrapped in <mark> elements with the following default styles:

The highlight uses the text-primary color with bold weight and no background, providing a subtle but clear indication of matching text.

Implementation Details

  • Case-insensitive matching: Query "hook" matches "Hook", "HOOK", etc.
  • Safe regex handling: Special regex characters in the query are escaped
  • Query length limit: Queries are limited to 100 characters for performance
  • Empty query handling: Returns the original text unchanged if query is empty or whitespace-only

Used By