]> BookStack Code Mirror - bookstack/commitdiff
Updated page includes to be top-level for code blocks
authorDan Brown <redacted>
Mon, 15 Nov 2021 00:48:05 +0000 (00:48 +0000)
committerDan Brown <redacted>
Mon, 15 Nov 2021 00:48:05 +0000 (00:48 +0000)
This change means that code blocks are now included still wrapped in
their pre tags, as we do for tables and lists.
Previously the <code> inner content would be included which would lead
to a generally bad/broken presentation.

Hopefully should not be a breaking change as section include tags for
code was tricky to get to, and it was in a semi-broken state.

For #2406

app/Entities/Tools/PageContent.php
tests/Entity/PageContentTest.php

index 52a10ae872ebbcf55827acf345296b20a4a327da..45bfe8fa1740bf0c9c33cbd2432967a74cd73547 100644 (file)
@@ -390,7 +390,7 @@ class PageContent
      */
     protected function fetchSectionOfPage(Page $page, string $sectionId): string
     {
-        $topLevelTags = ['table', 'ul', 'ol'];
+        $topLevelTags = ['table', 'ul', 'ol', 'pre'];
         $doc = $this->loadDocumentFromHtml($page->html);
 
         // Search included content for the id given and blank out if not exists.
index 0b99c63c3971ab92f393e90123c04053bba922a4..4dace533b1617242c22d3e057a966f2113bbd74f 100644 (file)
@@ -62,7 +62,9 @@ class PageContentTest extends TestCase
 
     public function test_page_includes_do_not_break_tables()
     {
+        /** @var Page $page */
         $page = Page::query()->first();
+        /** @var Page $secondPage */
         $secondPage = Page::query()->where('id', '!=', $page->id)->first();
 
         $content = '<table id="table"><tbody><tr><td>test</td></tr></tbody></table>';
@@ -72,8 +74,25 @@ class PageContentTest extends TestCase
         $page->html = "{{@{$secondPage->id}#table}}";
         $page->save();
 
-        $this->asEditor();
-        $pageResp = $this->get($page->getUrl());
+        $pageResp = $this->asEditor()->get($page->getUrl());
+        $pageResp->assertSee($content, false);
+    }
+
+    public function test_page_includes_do_not_break_code()
+    {
+        /** @var Page $page */
+        $page = Page::query()->first();
+        /** @var Page $secondPage */
+        $secondPage = Page::query()->where('id', '!=', $page->id)->first();
+
+        $content = '<pre id="bkmrk-code"><code>var cat = null;</code></pre>';
+        $secondPage->html = $content;
+        $secondPage->save();
+
+        $page->html = "{{@{$secondPage->id}#bkmrk-code}}";
+        $page->save();
+
+        $pageResp = $this->asEditor()->get($page->getUrl());
         $pageResp->assertSee($content, false);
     }