File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
src/Symfony/Component/Notifier/Bridge/Bluesky Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff line change @@ -208,6 +208,24 @@ private function parseFacets(string $input): array
208
208
];
209
209
}
210
210
211
+ // partial/naive URL regex based on: https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/util.ts
212
+ // https://github.com/bluesky-social/atproto/blob/main/packages/api/src/rich-text/detection.ts
213
+ $ regex = '/(?:^|\s)(#[\p{L}\p{N}]+)/u ' ;
214
+ foreach ($ this ->getMatchAndPosition ($ text , $ regex ) as $ match ) {
215
+ $ facets [] = [
216
+ 'index ' => [
217
+ 'byteStart ' => $ match [&
8000
#39;start ' ],
218
+ 'byteEnd ' => $ match ['end ' ],
219
+ ],
220
+ 'features ' => [
221
+ [
222
+ '$type ' => 'app.bsky.richtext.facet#tag ' ,
223
+ 'tag ' => substr ($ match ['match ' ], 1 ),
224
+ ],
225
+ ],
226
+ ];
227
+ }
228
+
211
229
return $ facets ;
212
230
}
213
231
Original file line number Diff line number Diff line change @@ -238,6 +238,39 @@ public function testParseFacetsUrlWithEmoji()
238
238
$ this ->assertEquals ($ expected , $ output );
239
239
}
240
240
241
+ public function testParseFacetsHashTags ()
242
+ {
243
+ $ input = 'Salut #test #123 #テスト http://bsky.app ' ;
244
+ $ expected = [
245
+ [
246
+ 'index ' => ['byteStart ' => 28 , 'byteEnd ' => 43 ],
247
+ 'features ' => [
248
+ ['$type ' => 'app.bsky.richtext.facet#link ' , 'uri ' => 'http://bsky.app ' ],
249
+ ],
250
+ ],
251
+ [
252
+ 'index ' => ['byteStart ' => 6 , 'byteEnd ' => 11 ],
253
+ 'features ' => [
254
+ ['$type ' => 'app.bsky.richtext.facet#tag ' , 'tag ' => 'test ' ],
255
+ ],
256
+ ],
257
+ [
258
+ 'index ' => ['byteStart ' => 12 , 'byteEnd ' => 16 ],
259
+ 'features ' => [
260
+ ['$type ' => 'app.bsky.richtext.facet#tag ' , 'tag ' => '123 ' ],
261
+ ],
262
+ ],
263
+ [
264
+ 'index ' => ['byteStart ' => 17 , 'byteEnd ' => 27 ],
265
+ 'features ' => [
266
+ ['$type ' => 'app.bsky.richtext.facet#tag ' , 'tag ' => 'テスト ' ],
267
+ ],
268
+ ],
269
+ ];
270
+ $ output = $ this ->parseFacets ($ input );
271
+ $ this ->assertEquals ($ expected , $ output );
272
+ }
273
+
241
274
/**
242
275
* Example from https://github.com/bluesky-social/atproto-website/blob/main/examples/create_bsky_post.py.
243
276
*/
You can’t perform that action at this time.
0 commit comments