Skip to content

Commit 77f1252

Browse files
committed
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
1 parent b7d4bd5 commit 77f1252

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

app/Entities/Tools/PageContent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ public function getNavigation(string $htmlContent): array
379379
protected function headerNodesToLevelList(DOMNodeList $nodeList): array
380380
{
381381
$tree = collect($nodeList)->map(function (DOMElement $header) {
382-
$text = trim(str_replace("\xc2\xa0", '', $header->nodeValue));
382+
$text = trim(str_replace("\xc2\xa0", ' ', $header->nodeValue));
383383
$text = mb_substr($text, 0, 100);
384384

385385
return [

tests/Entity/PageContentTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,20 @@ public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
469469
], $navMap[2]);
470470
}
471471

472+
public function test_get_page_nav_respects_non_breaking_spaces()
473+
{
474+
$content = '<h1 id="testa">Hello&nbsp;There</h1>';
475+
$pageContent = new PageContent(new Page(['html' => $content]));
476+
$navMap = $pageContent->getNavigation($content);
477+
478+
$this->assertEquals([
479+
'nodeName' => 'h1',
480+
'link' => '#testa',
481+
'text' => 'Hello There',
482+
'level' => 1,
483+
], $navMap[0]);
484+
}
485+
472486
public function test_page_text_decodes_html_entities()
473487
{
474488
$page = $this->entities->page();

0 commit comments

Comments
 (0)