in packages/dom/src/highlight-text.ts [145:160]
function removeHighlight(highlightElement: HTMLElement) {
// If it has somehow been removed already, there is nothing to be done.
if (!highlightElement.parentNode) return;
if (highlightElement.childNodes.length === 1) {
highlightElement.replaceWith(highlightElement.firstChild as Node);
} else {
// If the highlight somehow contains multiple nodes now, move them all.
while (highlightElement.firstChild) {
highlightElement.parentNode.insertBefore(
highlightElement.firstChild,
highlightElement,
);
}
highlightElement.remove();
}
}