Show · Highlight
Highlight
highlight specific content

code demo

How to import

Semi support Highlight component since v2.24.0

Basic usage

You can specify keywords to be highlighted with searchWords and source text with sourceString

Specify highlight style

By default, the highlighted text will have its own text style, the text color is black, and the background color is --semi-yellow-4.
In dark mode, the text color is white, and the background color is --semi-yellow-2.
When you need to customize different highlight styles, you can specify them through highlightClassName, highlightStyle

Use Different Styles for Different Texts

After v2.71.0, it supports using different highlight styles for different highlighted texts. The searchWords is a string array by default. When an array of objects is passed in, the highlighted text can be specified through text, and the className and style can be specified separately at the same time.

Specify the highlight tag

Semi will wrap the text matching searchWords in sourceString with mark tag by default, you can also re-specify the tag through component

API Reference

Highlight

propertydescriptiontypedefault value
searchWordsexpected highlighted textstring[]''
sourceStringsource textstring
componentHighlight labelstringmark
highlightClassNameThe style class name of the highlight tagReactNode-
highlightStyleInline style for highlight tagsReactNode-
caseSensitiveIs case sensitivefalse-
autoEscapeWhether to automatically escapetrue-