diff --git a/src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php b/src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php index db8eff9e70f50..b1578e6506102 100644 --- a/src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php +++ b/src/Symfony/Component/Notifier/Bridge/Bluesky/BlueskyTransport.php @@ -208,6 +208,24 @@ private function parseFacets(string $input): array ]; } + // partial/naive URL regex based on: https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/util.ts + // https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/detection.ts + $regex = '/(?:^|\s)(#[\p{L}\p{N}]+)/u'; + foreach ($this->getMatchAndPosition($text, $regex) as $match) { + $facets[] = [ + 'index' => [ + 'byteStart' => $match['start'], + 'byteEnd' => $match['end'], + ], + 'features' => [ + [ + '$type' => 'app.bsky.richtext.facet#tag', + 'tag' => substr($match['match'], 1), + ], + ], + ]; + } + return $facets; } diff --git a/src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php b/src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php index 09323174d8ce3..c5a7ce0725ad0 100644 --- a/src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php +++ b/src/Symfony/Component/Notifier/Bridge/Bluesky/Tests/BlueskyTransportTest.php @@ -238,6 +238,39 @@ public function testParseFacetsUrlWithEmoji() $this->assertEquals($expected, $output); } + public function testParseFacetsHashTags() + { + $input = 'Salut #test #123 #テスト http://bsky.app'; + $expected = [ + [ + 'index' => ['byteStart' => 28, 'byteEnd' => 43], + 'features' => [ + ['$type' => 'app.bsky.richtext.facet#link', 'uri' => 'http://bsky.app'], + ], + ], + [ + 'index' => ['byteStart' => 6, 'byteEnd' => 11], + 'features' => [ + ['$type' => 'app.bsky.richtext.facet#tag', 'tag' => 'test'], + ], + ], + [ + 'index' => ['byteStart' => 12, 'byteEnd' => 16], + 'features' => [ + ['$type' => 'app.bsky.richtext.facet#tag', 'tag' => '123'], + ], + ], + [ + 'index' => ['byteStart' => 17, 'byteEnd' => 27], + 'features' => [ + ['$type' => 'app.bsky.richtext.facet#tag', 'tag' => 'テスト'], + ], + ], + ]; + $output = $this->parseFacets($input); + $this->assertEquals($expected, $output); + } + /** * Example from https://github.com/bluesky-social/atproto-website/blob/main/examples/create_bsky_post.py. */
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: