File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff 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 [
Original file line number Diff line number Diff 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 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 ();
You can’t perform that action at this time.
0 commit comments