diff --git a/src/Models/Comment.php b/src/Models/Comment.php index 48eb5f5..845288e 100644 --- a/src/Models/Comment.php +++ b/src/Models/Comment.php @@ -2,8 +2,6 @@ namespace Relaticle\Comments\Models; -use Filament\Forms\Components\RichEditor\MentionProvider; -use Filament\Forms\Components\RichEditor\RichContentRenderer; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -149,33 +147,24 @@ class Comment extends Model { $body = $this->body; - if ($this->hasRichEditorMentions($body)) { - return RichContentRenderer::make($body) - ->mentions([ - MentionProvider::make('@') - ->getLabelsUsing(fn (array $ids): array => CommentsConfig::getCommenterModel()::query() - ->whereIn('id', $ids) - ->pluck('name', 'id') - ->all()), - ]) - ->toHtml(); - } - $mentionNames = $this->mentions->pluck('name')->filter()->unique(); foreach ($mentionNames as $name) { $escapedName = e($name); $styledSpan = '@'.$escapedName.''; + // Replace rich-editor mention spans (data-type="mention" with @Name as text content) + $body = preg_replace( + '/<(?:span|a)[^>]*data-type="mention"[^>]*>@?' . preg_quote($escapedName, '/') . '<\/(?:span|a)>/', + $styledSpan, + $body + ); + + // Replace plain-text mentions $body = str_replace("@{$name}", $styledSpan, $body); $body = str_replace("@{$name}", $styledSpan, $body); } return $body; } - - protected function hasRichEditorMentions(string $body): bool - { - return str_contains($body, 'data-type="mention"') || str_contains($body, '

') || str_contains($body, '