diff --git a/app/Entities/Tools/PageContent.php b/app/Entities/Tools/PageContent.php index 45bfe8fa1..c8204a181 100644 --- a/app/Entities/Tools/PageContent.php +++ b/app/Entities/Tools/PageContent.php @@ -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) { diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index 4dace533b..9524186c8 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -670,4 +670,24 @@ class PageContentTest extends TestCase $page->refresh(); $this->assertStringContainsString('html); } + + public function test_nested_headers_gets_assigned_an_id() + { + $this->asEditor(); + $page = Page::query()->first(); + + $content = '
Simple Test |