File size: 710 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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

```js
const html = '<div>hello world</div>';
const highlighted = highlight( 'hello', html );
```

Will produce:

```html
<div><mark>hello</mark> world</div>
```

Using a custom highlight wrapper:

```js
const customWrapper = document.createElement( 'span' );
customWrapper.setAttribute( 'class', 'my-wrapper' );

const customHighlighted = highlight( 'hello', html, customWrapper );
```

Will produce:

```html
<div><span class="my-wrapper">hello</span> world</div>
```