mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-08-26 12:16:07 +00:00
parent
7bb336d1a8
commit
359b1b40a2
@ -690,6 +690,7 @@ class EntityRepo
|
|||||||
preg_match_all("/{{@\s?([0-9].*?)}}/", $content, $matches);
|
preg_match_all("/{{@\s?([0-9].*?)}}/", $content, $matches);
|
||||||
if (count($matches[0]) === 0) return $content;
|
if (count($matches[0]) === 0) return $content;
|
||||||
|
|
||||||
|
$topLevelTags = ['table', 'ul', 'ol'];
|
||||||
foreach ($matches[1] as $index => $includeId) {
|
foreach ($matches[1] as $index => $includeId) {
|
||||||
$splitInclude = explode('#', $includeId, 2);
|
$splitInclude = explode('#', $includeId, 2);
|
||||||
$pageId = intval($splitInclude[0]);
|
$pageId = intval($splitInclude[0]);
|
||||||
@ -714,9 +715,14 @@ class EntityRepo
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$innerContent = '';
|
$innerContent = '';
|
||||||
|
$isTopLevel = in_array(strtolower($matchingElem->nodeName), $topLevelTags);
|
||||||
|
if ($isTopLevel) {
|
||||||
|
$innerContent .= $doc->saveHTML($matchingElem);
|
||||||
|
} else {
|
||||||
foreach ($matchingElem->childNodes as $childNode) {
|
foreach ($matchingElem->childNodes as $childNode) {
|
||||||
$innerContent .= $doc->saveHTML($childNode);
|
$innerContent .= $doc->saveHTML($childNode);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$content = str_replace($matches[0][$index], trim($innerContent), $content);
|
$content = str_replace($matches[0][$index], trim($innerContent), $content);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ class PageContentTest extends TestCase
|
|||||||
public function test_page_includes()
|
public function test_page_includes()
|
||||||
{
|
{
|
||||||
$page = Page::first();
|
$page = Page::first();
|
||||||
$secondPage = Page::all()->get(2);
|
$secondPage = Page::where('id', '!=', $page->id)->first();
|
||||||
|
|
||||||
$secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>";
|
$secondPage->html = "<p id='section1'>Hello, This is a test</p><p id='section2'>This is a second block of content</p>";
|
||||||
$secondPage->save();
|
$secondPage->save();
|
||||||
@ -38,7 +38,7 @@ class PageContentTest extends TestCase
|
|||||||
public function test_saving_page_with_includes()
|
public function test_saving_page_with_includes()
|
||||||
{
|
{
|
||||||
$page = Page::first();
|
$page = Page::first();
|
||||||
$secondPage = Page::all()->get(2);
|
$secondPage = Page::where('id', '!=', $page->id)->first();
|
||||||
$this->asEditor();
|
$this->asEditor();
|
||||||
$page->html = "<p>{{@$secondPage->id}}</p>";
|
$page->html = "<p>{{@$secondPage->id}}</p>";
|
||||||
|
|
||||||
@ -50,6 +50,23 @@ class PageContentTest extends TestCase
|
|||||||
$this->assertContains("{{@$secondPage->id}}", $page->html);
|
$this->assertContains("{{@$secondPage->id}}", $page->html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_page_includes_do_not_break_tables()
|
||||||
|
{
|
||||||
|
$page = Page::first();
|
||||||
|
$secondPage = Page::where('id', '!=', $page->id)->first();
|
||||||
|
|
||||||
|
$content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>';
|
||||||
|
$secondPage->html = $content;
|
||||||
|
$secondPage->save();
|
||||||
|
|
||||||
|
$page->html = "{{@{$secondPage->id}#table}}";
|
||||||
|
$page->save();
|
||||||
|
|
||||||
|
$this->asEditor();
|
||||||
|
$pageResp = $this->get($page->getUrl());
|
||||||
|
$pageResp->assertSee($content);
|
||||||
|
}
|
||||||
|
|
||||||
public function test_page_revision_views_viewable()
|
public function test_page_revision_views_viewable()
|
||||||
{
|
{
|
||||||
$this->asEditor();
|
$this->asEditor();
|
||||||
|
Loading…
Reference in New Issue
Block a user