feat(PageContent): set unique ids on nested headers

This commit is contained in:
julesdevops
2021-11-18 23:01:37 +01:00
parent 05ef23d34e
commit f8c16494fd
2 changed files with 29 additions and 0 deletions

View File

@ -193,6 +193,15 @@ class PageContent
}
}
// Set ids on nested header nodes
$nestedHeaders = $xPath->query('//body//*//h1|//body//*//h2|//body//*//h3|//body//*//h4|//body//*//h5|//body//*//h6');
foreach ($nestedHeaders as $nestedHeader) {
[$oldId, $newId] = $this->setUniqueId($nestedHeader, $idMap);
if ($newId && $newId !== $oldId) {
$this->updateLinks($xPath, '#' . $oldId, '#' . $newId);
}
}
// Ensure no duplicate ids within child items
$idElems = $xPath->query('//body//*//*[@id]');
foreach ($idElems as $domElem) {