UNPKG

@wordpress/components

Version:
30 lines (24 loc) 654 B
import { createElement } from "@wordpress/element"; /** * External dependencies */ import { escapeRegExp } from 'lodash'; /** * WordPress dependencies */ import { createInterpolateElement } from '@wordpress/element'; const TextHighlight = ({ text = '', highlight = '' }) => { const trimmedHighlightText = highlight.trim(); if (!trimmedHighlightText) { return text; } const regex = new RegExp(`(${escapeRegExp(trimmedHighlightText)})`, 'gi'); return createInterpolateElement(text.replace(regex, '<mark>$&</mark>'), { mark: createElement("mark", null) }); }; export default TextHighlight; //# sourceMappingURL=index.js.map