UNPKG

@wordpress/components

Version:
29 lines (28 loc) • 1.05 kB
import { findAll } from "highlight-words-core"; import { createElement } from "@wordpress/element"; // packages/components/src/text/utils.ts /** * Creates the highlighted text rendered by Text. * * @param options Highlighter options. * @param options.autoEscape Whether to escape regular-expression characters. * @param options.caseSensitive Whether matching is case-sensitive. * @param options.children Text to highlight. * @param options.sanitize Text normalization function used for matching. * @param options.searchWords Search terms to highlight. */ function createHighlighterText({ autoEscape, caseSensitive = false, children, sanitize, searchWords = [] }) { if (!children) return null; return findAll({ autoEscape, caseSensitive, sanitize, searchWords, textToHighlight: children }).map((chunk, index) => createElement(chunk.highlight ? "mark" : "span", { children: children.slice(chunk.start, chunk.end), key: index })); } export { createHighlighterText }; //# sourceMappingURL=utils.mjs.map