]> BookStack Code Mirror - bookstack/commitdiff
Input WYSIWYG: Aligned newline handling with old descriptions
authorDan Brown <redacted>
Wed, 20 Dec 2023 17:40:58 +0000 (17:40 +0000)
committerDan Brown <redacted>
Wed, 20 Dec 2023 17:40:58 +0000 (17:40 +0000)
To ensure consistenent behaviour before/after changes.
Added tests to cover.

app/Entities/Models/HasHtmlDescription.php
resources/views/books/show.blade.php
resources/views/chapters/show.blade.php
resources/views/shelves/show.blade.php
tests/Entity/BookShelfTest.php
tests/Entity/BookTest.php
tests/Entity/ChapterTest.php

index cc431f7fc7b1eabd8d6cd8b9a4a32fa4cdd429e1..c9f08616dbdc70c32a0bcdc10f31604b00d7833b 100644 (file)
@@ -15,7 +15,7 @@ trait HasHtmlDescription
      */
     public function descriptionHtml(): string
     {
-        $html = $this->description_html ?: '<p>' . e($this->description) . '</p>';
+        $html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
         return HtmlContentFilter::removeScriptsFromHtmlString($html);
     }
 }
index 5884e41fde8f978f982b884e9022214f7352077b..dbb09fc9e877eb1e51513dd0640087dcb4c40947 100644 (file)
@@ -26,7 +26,7 @@
     <main class="content-wrap card">
         <h1 class="break-text">{{$book->name}}</h1>
         <div refs="entity-search@contentView" class="book-content">
-            <p class="text-muted">{!! $book->descriptionHtml() !!}</p>
+            <div class="text-muted break-text">{!! $book->descriptionHtml() !!}</div>
             @if(count($bookChildren) > 0)
                 <div class="entity-list book-contents">
                     @foreach($bookChildren as $childElement)
index 6fe1ce431a242dd8db47e2cbd8d892da09101c48..45e43ad96a91dda5862e8f26d422e0d129ed5c6d 100644 (file)
@@ -24,7 +24,7 @@
     <main class="content-wrap card">
         <h1 class="break-text">{{ $chapter->name }}</h1>
         <div refs="entity-search@contentView" class="chapter-content">
-            <p class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</p>
+            <div class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</div>
             @if(count($pages) > 0)
                 <div class="entity-list book-contents">
                     @foreach($pages as $page)
index e475a8080aaa0d75ec89e709d49c59b51e0e6a00..11baccaf46354db6bb6a2395d7fd2f7b268fc41f 100644 (file)
@@ -28,7 +28,7 @@
         </div>
 
         <div class="book-content">
-            <p class="text-muted">{!! $shelf->descriptionHtml() !!}</p>
+            <div class="text-muted break-text">{!! $shelf->descriptionHtml() !!}</div>
             @if(count($sortedVisibleShelfBooks) > 0)
                 @if($view === 'list')
                     <div class="entity-list">
index 7f6542d5c710d4f4abfc5d61666fcfcf0edabeaa..fb9862931ae4c211cdc9a184fa533d2f41a00dc5 100644 (file)
@@ -403,4 +403,15 @@ class BookShelfTest extends TestCase
         $resp = $this->asEditor()->get($shelf->getUrl('/create-book'));
         $this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel');
     }
+
+    public function test_show_view_displays_description_if_no_description_html_set()
+    {
+        $shelf = $this->entities->shelf();
+        $shelf->description_html = '';
+        $shelf->description = "My great\ndescription\n\nwith newlines";
+        $shelf->save();
+
+        $resp = $this->asEditor()->get($shelf->getUrl());
+        $resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
+    }
 }
index c4872785b88fc2be9df3b623368262090a296630..3740892460b296e44b7d4c88e17afb6c7709d421 100644 (file)
@@ -278,6 +278,17 @@ class BookTest extends TestCase
         $this->assertEquals($expected, $book->description_html);
     }
 
+    public function test_show_view_displays_description_if_no_description_html_set()
+    {
+        $book = $this->entities->book();
+        $book->description_html = '';
+        $book->description = "My great\ndescription\n\nwith newlines";
+        $book->save();
+
+        $resp = $this->asEditor()->get($book->getUrl());
+        $resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
+    }
+
     public function test_show_view_has_copy_button()
     {
         $book = $this->entities->book();
index a057d91b5603eab598add61c85881a97caccb9df..1577cee76d8ae24c58382111caac2fc7aabc0b66 100644 (file)
@@ -31,6 +31,17 @@ class ChapterTest extends TestCase
         $resp->assertSee($chapter->description_html, false);
     }
 
+    public function test_show_view_displays_description_if_no_description_html_set()
+    {
+        $chapter = $this->entities->chapter();
+        $chapter->description_html = '';
+        $chapter->description = "My great\ndescription\n\nwith newlines";
+        $chapter->save();
+
+        $resp = $this->asEditor()->get($chapter->getUrl());
+        $resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
+    }
+
     public function test_delete()
     {
         $chapter = Chapter::query()->whereHas('pages')->first();