doc/lib: Fix that highlighting a search messes up the text around the match

refs #6630
This commit is contained in:
Eric Lippmann 2015-02-11 13:48:23 +01:00
parent 54292eed20
commit 195aa581cb
1 changed files with 6 additions and 7 deletions

View File

@ -141,16 +141,15 @@ class SectionRenderer extends Renderer
$matches = $match->getMatches();
ksort($matches);
$offset = 0;
$parentNode = $node->parentNode;
/** @type \DOMElement $parentNode */
$parentNode->removeChild($node);
$fragment = $doc->createDocumentFragment();
foreach ($matches as $position => $match) {
$parentNode->appendChild($doc->createTextNode(substr($text, $offset, $position - $offset)));
$parentNode->appendChild($doc->createElement('span', $match))
->setAttribute('class', DocSearchMatch::HIGHLIGHT_CSS_CLASS);
$fragment->appendChild($doc->createTextNode(substr($text, $offset, $position - $offset)));
$fragment->appendChild($doc->createElement('span', $match))
->setAttribute('class', DocSearchMatch::HIGHLIGHT_CSS_CLASS);
$offset = $position + strlen($match);
}
$parentNode->appendChild($doc->createTextNode(substr($text, $offset)));
$fragment->appendChild($doc->createTextNode(substr($text, $offset)));
$node->parentNode->replaceChild($fragment, $node);
}
return $doc->saveHTML();
}