{
const elem = html`<div style="max-width: 640px;" contentEditable="true"></div>`
elem.textContent = text
if (window.CSS.highlights && window.Highlight) {
const node = elem.childNodes[0]
const ranges = textRanges.map(textRange => {
const range = document.createRange()
range.setStart(node, textRange.start)
range.setEnd(node, textRange.end)
return range
})
const highlight = new window.Highlight(...ranges);
window.CSS.highlights.clear()
window.CSS.highlights.set("user-1-highlight", highlight);
}
const style = html`
<style>
::highlight(user-1-highlight) {
background-color: yellow;
color: black;
text-decoration: underline;
}
</style>
`
const root = document.createElement("root");
root.appendChild(elem)
root.appendChild(style)
elem.innerHTML = text
if (window.CSS.highlights && window.Highlight) {
const node = elem.childNodes[0]
const ranges = textRanges.map(textRange => {
const range = document.createRange()
range.setStart(node, textRange.start)
range.setEnd(node, textRange.end)
return range
})
const highlight = new window.Highlight(...ranges);
window.CSS.highlights.clear()
window.CSS.highlights.set("user-1-highlight", highlight);
}
return root
}