Skip to content

Commit ed5d67e

Browse files
committed
Input WYSIWYG: Aligned newline handling with old descriptions
To ensure consistenent behaviour before/after changes. Added tests to cover.
1 parent a21ca44 commit ed5d67e

File tree

7 files changed

+37
-4
lines changed

7 files changed

+37
-4
lines changed

app/Entities/Models/HasHtmlDescription.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ trait HasHtmlDescription
1515
*/
1616
public function descriptionHtml(): string
1717
{
18-
$html = $this->description_html ?: '<p>' . e($this->description) . '</p>';
18+
$html = $this->description_html ?: '<p>' . nl2br(e($this->description)) . '</p>';
1919
return HtmlContentFilter::removeScriptsFromHtmlString($html);
2020
}
2121
}

resources/views/books/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<main class="content-wrap card">
2727
<h1 class="break-text">{{$book->name}}</h1>
2828
<div refs="entity-search@contentView" class="book-content">
29-
<p class="text-muted">{!! $book->descriptionHtml() !!}</p>
29+
<div class="text-muted break-text">{!! $book->descriptionHtml() !!}</div>
3030
@if(count($bookChildren) > 0)
3131
<div class="entity-list book-contents">
3232
@foreach($bookChildren as $childElement)

resources/views/chapters/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<main class="content-wrap card">
2525
<h1 class="break-text">{{ $chapter->name }}</h1>
2626
<div refs="entity-search@contentView" class="chapter-content">
27-
<p class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</p>
27+
<div class="text-muted break-text">{!! $chapter->descriptionHtml() !!}</div>
2828
@if(count($pages) > 0)
2929
<div class="entity-list book-contents">
3030
@foreach($pages as $page)

resources/views/shelves/show.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</div>
2929

3030
<div class="book-content">
31-
<p class="text-muted">{!! $shelf->descriptionHtml() !!}</p>
31+
<div class="text-muted break-text">{!! $shelf->descriptionHtml() !!}</div>
3232
@if(count($sortedVisibleShelfBooks) > 0)
3333
@if($view === 'list')
3434
<div class="entity-list">

tests/Entity/BookShelfTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,4 +403,15 @@ public function test_cancel_on_child_book_creation_returns_to_original_shelf()
403403
$resp = $this->asEditor()->get($shelf->getUrl('/create-book'));
404404
$this->withHtml($resp)->assertElementContains('form a[href="' . $shelf->getUrl() . '"]', 'Cancel');
405405
}
406+
407+
public function test_show_view_displays_description_if_no_description_html_set()
408+
{
409+
$shelf = $this->entities->shelf();
410+
$shelf->description_html = '';
411+
$shelf->description = "My great\ndescription\n\nwith newlines";
412+
$shelf->save();
413+
414+
$resp = $this->asEditor()->get($shelf->getUrl());
415+
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
416+
}
406417
}

tests/Entity/BookTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,17 @@ public function test_description_limited_to_specific_html()
278278
$this->assertEquals($expected, $book->description_html);
279279
}
280280

281+
public function test_show_view_displays_description_if_no_description_html_set()
282+
{
283+
$book = $this->entities->book();
284+
$book->description_html = '';
285+
$book->description = "My great\ndescription\n\nwith newlines";
286+
$book->save();
287+
288+
$resp = $this->asEditor()->get($book->getUrl());
289+
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
290+
}
291+
281292
public function test_show_view_has_copy_button()
282293
{
283294
$book = $this->entities->book();

tests/Entity/ChapterTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ public function test_create()
3131
$resp->assertSee($chapter->description_html, false);
3232
}
3333

34+
public function test_show_view_displays_description_if_no_description_html_set()
35+
{
36+
$chapter = $this->entities->chapter();
37+
$chapter->description_html = '';
38+
$chapter->description = "My great\ndescription\n\nwith newlines";
39+
$chapter->save();
40+
41+
$resp = $this->asEditor()->get($chapter->getUrl());
42+
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
43+
}
44+
3445
public function test_delete()
3546
{
3647
$chapter = Chapter::query()->whereHas('pages')->first();

0 commit comments

Comments
 (0)