Skip to content

NOW MANAGED ON CODEBERG

Input WYSIWYG: Aligned newline handling with old descriptions

Dan Browned5d67e60956
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 ?: '<p>' . e($this->description) . '</p>';
+ $html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
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 @@
<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)
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 @@
<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)
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 @@
</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">
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("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", 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("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", 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("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
+ }
+
public function test_delete()
{
$chapter = Chapter::query()->whereHas('pages')->first();