feat(comments): add character limit to comment markdown body
Add an optional `$limit` parameter to `CommentPresenter::markdownBody()` that truncates the comment body before rendering Markdown. The comment partial now passes a default limit of 250 characters, preventing long comments from dominating the layout. Unit tests cover rendering with and without a limit.
This commit is contained in:
@@ -14,9 +14,15 @@ class CommentPresenter
|
||||
$this->comment = $comment;
|
||||
}
|
||||
|
||||
public function markdownBody()
|
||||
public function markdownBody(?int $limit = null)
|
||||
{
|
||||
return Str::of($this->comment->body)->markdown([
|
||||
$body = $this->comment->body;
|
||||
|
||||
if ($limit !== null) {
|
||||
$body = Str::limit($body, $limit);
|
||||
}
|
||||
|
||||
return Str::of($body)->markdown([
|
||||
'html_input' => 'strip',
|
||||
]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user