diff --git a/app/Repos/EntityRepo.php b/app/Repos/EntityRepo.php index c31ddfefe..24c680234 100644 --- a/app/Repos/EntityRepo.php +++ b/app/Repos/EntityRepo.php @@ -690,6 +690,7 @@ class EntityRepo preg_match_all("/{{@\s?([0-9].*?)}}/", $content, $matches); if (count($matches[0]) === 0) return $content; + $topLevelTags = ['table', 'ul', 'ol']; foreach ($matches[1] as $index => $includeId) { $splitInclude = explode('#', $includeId, 2); $pageId = intval($splitInclude[0]); @@ -714,8 +715,13 @@ class EntityRepo continue; } $innerContent = ''; - foreach ($matchingElem->childNodes as $childNode) { - $innerContent .= $doc->saveHTML($childNode); + $isTopLevel = in_array(strtolower($matchingElem->nodeName), $topLevelTags); + if ($isTopLevel) { + $innerContent .= $doc->saveHTML($matchingElem); + } else { + foreach ($matchingElem->childNodes as $childNode) { + $innerContent .= $doc->saveHTML($childNode); + } } $content = str_replace($matches[0][$index], trim($innerContent), $content); } diff --git a/tests/Entity/PageContentTest.php b/tests/Entity/PageContentTest.php index cd6526aec..370514788 100644 --- a/tests/Entity/PageContentTest.php +++ b/tests/Entity/PageContentTest.php @@ -9,7 +9,7 @@ class PageContentTest extends TestCase public function test_page_includes() { $page = Page::first(); - $secondPage = Page::all()->get(2); + $secondPage = Page::where('id', '!=', $page->id)->first(); $secondPage->html = "
Hello, This is a test
This is a second block of content
"; $secondPage->save(); @@ -38,7 +38,7 @@ class PageContentTest extends TestCase public function test_saving_page_with_includes() { $page = Page::first(); - $secondPage = Page::all()->get(2); + $secondPage = Page::where('id', '!=', $page->id)->first(); $this->asEditor(); $page->html = "{{@$secondPage->id}}
"; @@ -50,6 +50,23 @@ class PageContentTest extends TestCase $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 = 'test |