mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-05-04 18:08:46 +03:00
Descriptions: Improved empty field handling, reduces whitespace
For #5724
This commit is contained in:
@@ -50,6 +50,11 @@ class EntityHtmlDescription
|
||||
return $html;
|
||||
}
|
||||
|
||||
$isEmpty = empty(trim(strip_tags($html)));
|
||||
if ($isEmpty) {
|
||||
return '<p></p>';
|
||||
}
|
||||
|
||||
return HtmlContentFilter::removeActiveContentFromHtmlString($html);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<textarea component="wysiwyg-input"
|
||||
option:wysiwyg-input:text-direction="{{ $locale->htmlDirection() }}"
|
||||
id="description_html" name="description_html" rows="5"
|
||||
@if($errors->has('description_html')) class="text-neg" @endif>@if(isset($model) || old('description_html')){{ old('description_html') ?? $model->descriptionInfo()->getHtml() }}@endif</textarea>
|
||||
@if($errors->has('description_html')) class="text-neg" @endif>@if(isset($model) || old('description_html')){{ old('description_html') ?? $model->descriptionInfo()->getHtml() }}@else{{ '<p></p>' }}@endif</textarea>
|
||||
@if($errors->has('description_html'))
|
||||
<div class="text-neg text-small">{{ $errors->first('description_html') }}</div>
|
||||
@endif
|
||||
@@ -278,4 +278,25 @@ class BookTest extends TestCase
|
||||
$resp = $this->asEditor()->get($book->getUrl());
|
||||
$resp->assertSee("<p>My great<br>\ndescription<br>\n<br>\nwith newlines</p>", false);
|
||||
}
|
||||
|
||||
public function test_description_with_only_br_tags_results_in_empty_p_tag_used_on_show()
|
||||
{
|
||||
$descriptions = [
|
||||
'<p><br></p>',
|
||||
'<p><br><br><br><br></p>',
|
||||
'<p><br><br><br></p><h1><br><br><br><br><br></h1>',
|
||||
];
|
||||
$book = $this->entities->book();
|
||||
$this->asEditor();
|
||||
|
||||
foreach ($descriptions as $descriptionTestCase) {
|
||||
$book->description_html = $descriptionTestCase;
|
||||
$book->save();
|
||||
|
||||
$resp = $this->get($book->getUrl());
|
||||
$html = $this->withHtml($resp);
|
||||
$descriptionHtml = $html->getInnerHtml('.book-content > div.text-muted:first-child');
|
||||
$this->assertEquals('<p></p>', $descriptionHtml);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user