Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions app/Entities/Tools/PageContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,15 @@ protected function formatHtml(string $htmlText): string
}
}

// 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) {
Expand Down
20 changes: 20 additions & 0 deletions tests/Entity/PageContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -670,4 +670,24 @@ public function test_base64_images_within_markdown_blanked_if_not_supported_exte
$page->refresh();
$this->assertStringContainsString('<img src=""', $page->html);
}

public function test_nested_headers_gets_assigned_an_id()
{
$this->asEditor();
$page = Page::query()->first();

$content = '<table><tbody><tr><td><h5>Simple Test</h5></td></tr></tbody></table>';
$this->put($page->getUrl(), [
'name' => $page->name,
'html' => $content,
'summary' => '',
]);

$updatedPage = Page::query()->where('id', '=', $page->id)->first();

// The top level <table> node will get assign the bkmrk-simple-test id because the system will
// take the node value of h5
// So the h5 should get the bkmrk-simple-test-1 id
$this->assertStringContainsString('<h5 id="bkmrk-simple-test-1">Simple Test</h5>', $updatedPage->html);
}
}