TextHighlight 是一个 WordPress 组件,用于在文本字符串中高亮显示指定字符串的匹配项。它通过将每个匹配项包裹在 标签中来实现,该标签提供浏览器默认样式。
import { TextHighlight } from '@wordpress/components';
const MyTextHighlight = () => (
<TextHighlight
text="Why do we like Gutenberg? Because Gutenberg is the best!"
highlight="Gutenberg"
/>
); Highlights occurrences of a given string within another string of text. Wraps each match with a <mark> tag which provides browser default styling.
Pass in the text and the highlight string to be matched against.
In the example below, the string Gutenberg would be highlighted twice.
import { TextHighlight } from '@wordpress/components';
const MyTextHighlight = () => (
<TextHighlight
text="Why do we like Gutenberg? Because Gutenberg is the best!"
highlight="Gutenberg"
/>
);
The component accepts the following props.
highlight: stringThe string to search for and highlight within the text. Case insensitive. Multiple matches.
''text: stringThe string of text to be tested for occurrences of then given highlight.
''