public function replace(DOMText $node) {
    if (preg_match($this->_pattern, $node->nodeValue)) {
      // split using the pattern, but capture the delimiter strings
      $parts = preg_split(
        $this->_pattern, $node->nodeValue, -1, PREG_SPLIT_DELIM_CAPTURE
      );
      $items = [];
      foreach ($parts as $part) {
        $string = strtolower($part);
        if (isset($this->_highlights[$string])) {
          $span = $node->ownerDocument->createElement('span');
          $items[] = FluentDOM($span)
            ->addClass($this->_highlights[$string])
            ->text($part)
            ->item(0);
        } else {
          $items[] = $node->ownerDocument->createTextNode($part);
        }
      }
      // replace the text node
      FluentDOM($node)->replaceWith($items);
    }
  }