Page nav: Fixed nbsp being represented as nothing

Now represented in page nav using a normal space to avoid complete
removal of space.
Added test to cover.
For #4836
This commit is contained in:
Dan Brown 2024-03-09 15:52:09 +00:00
parent b7d4bd5bce
commit 77f125208e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 15 additions and 1 deletions

View File

@ -379,7 +379,7 @@ class PageContent
protected function headerNodesToLevelList(DOMNodeList $nodeList): array protected function headerNodesToLevelList(DOMNodeList $nodeList): array
{ {
$tree = collect($nodeList)->map(function (DOMElement $header) { $tree = collect($nodeList)->map(function (DOMElement $header) {
$text = trim(str_replace("\xc2\xa0", '', $header->nodeValue)); $text = trim(str_replace("\xc2\xa0", ' ', $header->nodeValue));
$text = mb_substr($text, 0, 100); $text = mb_substr($text, 0, 100);
return [ return [

View File

@ -469,6 +469,20 @@ class PageContentTest extends TestCase
], $navMap[2]); ], $navMap[2]);
} }
public function test_get_page_nav_respects_non_breaking_spaces()
{
$content = '<h1 id="testa">Hello&nbsp;There</h1>';
$pageContent = new PageContent(new Page(['html' => $content]));
$navMap = $pageContent->getNavigation($content);
$this->assertEquals([
'nodeName' => 'h1',
'link' => '#testa',
'text' => 'Hello There',
'level' => 1,
], $navMap[0]);
}
public function test_page_text_decodes_html_entities() public function test_page_text_decodes_html_entities()
{ {
$page = $this->entities->page(); $page = $this->entities->page();