@wordpress/components
Version:
UI components for WordPress.
30 lines (24 loc) • 654 B
JavaScript
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