mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-27 12:41:58 +00:00
Updated page nav header shift logic to be accurate
Added tests to cover. Fixes #542
This commit is contained in:
parent
56e31a5df7
commit
fbb2b7ac6a
@ -438,10 +438,10 @@ class PageRepo extends EntityRepo
|
|||||||
return mb_strlen($header['text']) > 0;
|
return mb_strlen($header['text']) > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Normalise headers if only smaller headers have been used
|
// Shift headers if only smaller headers have been used
|
||||||
$minLevel = $tree->pluck('level')->min();
|
$levelChange = ($tree->pluck('level')->min() - 1);
|
||||||
$tree = $tree->map(function ($header) use ($minLevel) {
|
$tree = $tree->map(function ($header) use ($levelChange) {
|
||||||
$header['level'] -= ($minLevel - 2);
|
$header['level'] -= ($levelChange);
|
||||||
return $header;
|
return $header;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@
|
|||||||
padding-left: $nav-indent;
|
padding-left: $nav-indent;
|
||||||
}
|
}
|
||||||
.h2 {
|
.h2 {
|
||||||
padding-left: $nav-indent;
|
padding-left: $nav-indent * 1.5;
|
||||||
}
|
}
|
||||||
.h3 {
|
.h3 {
|
||||||
padding-left: $nav-indent * 2;
|
padding-left: $nav-indent * 2;
|
||||||
|
@ -16,6 +16,32 @@ class PageRepoTest extends TestCase
|
|||||||
$this->pageRepo = app()->make(PageRepo::class);
|
$this->pageRepo = app()->make(PageRepo::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_page_nav_sets_correct_properties()
|
||||||
|
{
|
||||||
|
$content = '<h1 id="testa">Hello</h1><h2 id="testb">There</h2><h3 id="testc">Donkey</h3>';
|
||||||
|
$navMap = $this->pageRepo->getPageNav($content);
|
||||||
|
|
||||||
|
$this->assertCount(3, $navMap);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h1',
|
||||||
|
'link' => '#testa',
|
||||||
|
'text' => 'Hello',
|
||||||
|
'level' => 1,
|
||||||
|
], $navMap[0]);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h2',
|
||||||
|
'link' => '#testb',
|
||||||
|
'text' => 'There',
|
||||||
|
'level' => 2,
|
||||||
|
], $navMap[1]);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h3',
|
||||||
|
'link' => '#testc',
|
||||||
|
'text' => 'Donkey',
|
||||||
|
'level' => 3,
|
||||||
|
], $navMap[2]);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_get_page_nav_does_not_show_empty_titles()
|
public function test_get_page_nav_does_not_show_empty_titles()
|
||||||
{
|
{
|
||||||
$content = '<h1 id="testa">Hello</h1><h2 id="testb"> </h2><h3 id="testc"></h3>';
|
$content = '<h1 id="testa">Hello</h1><h2 id="testb"> </h2><h3 id="testc"></h3>';
|
||||||
@ -29,4 +55,24 @@ class PageRepoTest extends TestCase
|
|||||||
], $navMap[0]);
|
], $navMap[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_get_page_nav_shifts_headers_if_only_smaller_ones_are_used()
|
||||||
|
{
|
||||||
|
$content = '<h4 id="testa">Hello</h4><h5 id="testb">There</h5><h6 id="testc">Donkey</h6>';
|
||||||
|
$navMap = $this->pageRepo->getPageNav($content);
|
||||||
|
|
||||||
|
$this->assertCount(3, $navMap);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h4',
|
||||||
|
'level' => 1,
|
||||||
|
], $navMap[0]);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h5',
|
||||||
|
'level' => 2,
|
||||||
|
], $navMap[1]);
|
||||||
|
$this->assertArraySubset([
|
||||||
|
'nodeName' => 'h6',
|
||||||
|
'level' => 3,
|
||||||
|
], $navMap[2]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user