This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: highlighter results

#53501
kerry_avxzkerry_avxz
Participant

Ah ok no worries, that explains it 🙂

I have written some script to get around it for now:

document.addEventListener("DOMContentLoaded", function () {
  const params = new URLSearchParams(window.location.search);
  const keyword = params.get('asp_ls');
  if (!keyword) return;

  const container = document.querySelector('#highlighter');
  if (!container) return;

  const regex = new RegExp(<code>(${keyword})</code>, 'gi');

  // Recursive function to walk through text nodes
  function highlightTextNodes(node) {
    if (node.nodeType === Node.TEXT_NODE) {
      if (regex.test(node.textContent)) {
        const span = document.createElement('span');
        span.innerHTML = node.textContent.replace(regex, '<mark>$1</mark>');
        node.replaceWith(span);
      }
    } else if (node.nodeType === Node.ELEMENT_NODE && node.nodeName !== "SCRIPT" && node.nodeName !== "STYLE") {
      for (let i = 0; i < node.childNodes.length; i++) {
        highlightTextNodes(node.childNodes[i]);
      }
    }
  }

  highlightTextNodes(container);
});