feat: Refactor mention rendering and generator classes

- Add support for Mastodon username mentions
- Add test for parsing Mastodon usernames in notes
- Modify namespace and class imports for `MentionGenerator` and `MentionRenderer` in `Note.php`
- Rename `ContactMentionGenerator.php` to `MentionGenerator.php`
This commit is contained in:
Jonny Barnes 2023-11-19 17:22:02 +00:00
parent 3817545cf3
commit 05c63b241d
Signed by: jonny
SSH key fingerprint: SHA256:CTuSlns5U7qlD9jqHvtnVmfYV3Zwl2Z7WnJ4/dqOaL8
5 changed files with 55 additions and 31 deletions

View file

@ -4,8 +4,8 @@ declare(strict_types=1);
namespace App\Models;
use App\CommonMark\Generators\ContactMentionGenerator;
use App\CommonMark\Renderers\ContactMentionRenderer;
use App\CommonMark\Generators\MentionGenerator;
use App\CommonMark\Renderers\MentionRenderer;
use Codebird\Codebird;
use Exception;
use GuzzleHttp\Client;
@ -385,10 +385,10 @@ class Note extends Model
{
$config = [
'mentions' => [
'contacts_handle' => [
'mentions_handle' => [
'prefix' => '@',
'pattern' => '[a-z\d](?:[a-z\d]|-(?=[a-z\d])){0,38}(?!\w)',
'generator' => new ContactMentionGenerator(),
'pattern' => '([\w@.])+(\b)',
'generator' => new MentionGenerator(),
],
],
];
@ -397,7 +397,7 @@ class Note extends Model
$environment->addExtension(new CommonMarkCoreExtension());
$environment->addExtension(new AutolinkExtension());
$environment->addExtension(new MentionExtension());
$environment->addRenderer(Mention::class, new ContactMentionRenderer());
$environment->addRenderer(Mention::class, new MentionRenderer());
$environment->addRenderer(FencedCode::class, new FencedCodeRenderer());
$environment->addRenderer(IndentedCode::class, new IndentedCodeRenderer());
$markdownConverter = new MarkdownConverter($environment);