diff --git a/app/Entities/Models/HasHtmlDescription.php b/app/Entities/Models/HasHtmlDescription.php index cc431f7fc..c9f08616d 100644 --- a/app/Entities/Models/HasHtmlDescription.php +++ b/app/Entities/Models/HasHtmlDescription.php @@ -15,7 +15,7 @@ trait HasHtmlDescription */ public function descriptionHtml(): string { - $html = $this->description_html ?: '

' . e($this->description) . '

'; + $html = $this->description_html ?: '

' . nl2br(e($this->description)) . '

'; return HtmlContentFilter::removeScriptsFromHtmlString($html); } } diff --git a/resources/views/books/show.blade.php b/resources/views/books/show.blade.php index 5884e41fd..dbb09fc9e 100644 --- a/resources/views/books/show.blade.php +++ b/resources/views/books/show.blade.php @@ -26,7 +26,7 @@

{{$book->name}}

-

{!! $book->descriptionHtml() !!}

+
{!! $book->descriptionHtml() !!}
@if(count($bookChildren) > 0)
@foreach($bookChildren as $childElement) diff --git a/resources/views/chapters/show.blade.php b/resources/views/chapters/show.blade.php index 6fe1ce431..45e43ad96 100644 --- a/resources/views/chapters/show.blade.php +++ b/resources/views/chapters/show.blade.php @@ -24,7 +24,7 @@

{{ $chapter->name }}

-

{!! $chapter->descriptionHtml() !!}

+
{!! $chapter->descriptionHtml() !!}
@if(count($pages) > 0)
@foreach($pages as $page) diff --git a/resources/views/shelves/show.blade.php b/resources/views/shelves/show.blade.php index e475a8080..11baccaf4 100644 --- a/resources/views/shelves/show.blade.php +++ b/resources/views/shelves/show.blade.php @@ -28,7 +28,7 @@
-

{!! $shelf->descriptionHtml() !!}

+
{!! $shelf->descriptionHtml() !!}
@if(count($sortedVisibleShelfBooks) > 0) @if($view === 'list')
diff --git a/tests/Entity/BookShelfTest.php b/tests/Entity/BookShelfTest.php index 7f6542d5c..fb9862931 100644 --- a/tests/Entity/BookShelfTest.php +++ b/tests/Entity/BookShelfTest.php @@ -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("

My great
\ndescription
\n
\nwith newlines

", false); + } } diff --git a/tests/Entity/BookTest.php b/tests/Entity/BookTest.php index c4872785b..374089246 100644 --- a/tests/Entity/BookTest.php +++ b/tests/Entity/BookTest.php @@ -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("

My great
\ndescription
\n
\nwith newlines

", false); + } + public function test_show_view_has_copy_button() { $book = $this->entities->book(); diff --git a/tests/Entity/ChapterTest.php b/tests/Entity/ChapterTest.php index a057d91b5..1577cee76 100644 --- a/tests/Entity/ChapterTest.php +++ b/tests/Entity/ChapterTest.php @@ -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("

My great
\ndescription
\n
\nwith newlines

", false); + } + public function test_delete() { $chapter = Chapter::query()->whereHas('pages')->first();