highlight
This module searches a given html string and wraps all matching strings with a <mark> or a custom wrapper.
If you give a custom element as a wrapper, it will be cloned every time it is added via cloneNode()
How to use
const html = '<div>hello world</div>';
const highlighted = highlight( 'hello', html );
Will produce:
<div><mark>hello</mark> world</div>
Using a custom highlight wrapper:
const customWrapper = document.createElement( 'span' );
customWrapper.setAttribute( 'class', 'my-wrapper' );
const customHighlighted = highlight( 'hello', html, customWrapper );
Will produce:
<div><span class="my-wrapper">hello</span> world</div>