How to highlight text in repeater search results

This is where I’m at with the code and it works great except for the HTML piece:


$w ( ‘#GlossaryRepeater’ ). forEachItem (( $item , itemData )=>{
let searchInput = $w ( ‘#SearchBar’ ). value
let searchResult = new RegExp ( searchInput , “gi” );
let newText = $item ( ‘#definitionText’ ). text . replace ( searchResult , ( match ) => <mark> ${ match } </mark> )

$item ( '#definitionText' ). text  =  newText 
}) 

I also tried using a separate text element to display the search input text, highlight with HTML and then put back in the repeater. The 3rd line for that looked like this:


let  newText  =  $item ( '#definitionText' ). text . replace ( searchResult ,  $w ( "#text" ). html  =  `<p style="background-color:yellow;font-size: 18px"> ${ searchInput } </p>` ; 

…in both cases I’m having trouble using HTML in the 2nd argument for the replace() function.

Does anyone have any input? Thanks again!