(text: string, status: APIStatus)
| 266 | }; |
| 267 | |
| 268 | const formatStatus = (text: string, status: APIStatus) => { |
| 269 | const enableFacets = false; |
| 270 | |
| 271 | if (status.raw_text && enableFacets) { |
| 272 | const plainText = status.raw_text.text; |
| 273 | text = plainText; |
| 274 | |
| 275 | const noteTweetUnicodeScalarFacets = |
| 276 | status.provider === DataProvider.Twitter && (status as APITwitterStatus).is_note_tweet; |
| 277 | |
| 278 | const facetUtf16RangesOnPlain = status.raw_text.facets.map(f => |
| 279 | facetUtf16RangeOnPlainText(plainText, f, noteTweetUnicodeScalarFacets) |
| 280 | ); |
| 281 | |
| 282 | let baseHashtagUrl = ''; |
| 283 | let baseSymbolUrl = ''; |
| 284 | let baseMentionUrl = ''; |
| 285 | |
| 286 | switch (status.provider) { |
| 287 | case DataProvider.Bluesky: |
| 288 | baseHashtagUrl = `${Constants.BLUESKY_ROOT}/hashtag`; |
| 289 | baseSymbolUrl = `${Constants.BLUESKY_ROOT}/search?q=%24`; |
| 290 | baseMentionUrl = `${Constants.BLUESKY_ROOT}/profile/`; |
| 291 | break; |
| 292 | case DataProvider.Twitter: |
| 293 | baseHashtagUrl = `${Constants.TWITTER_ROOT}/hashtag`; |
| 294 | baseSymbolUrl = `${Constants.TWITTER_ROOT}/search?q=%24`; |
| 295 | baseMentionUrl = `${Constants.TWITTER_ROOT}/`; |
| 296 | break; |
| 297 | case DataProvider.TikTok: |
| 298 | baseHashtagUrl = `${Constants.TIKTOK_ROOT}/tag`; |
| 299 | baseSymbolUrl = `${Constants.TIKTOK_ROOT}/search?q=%24`; |
| 300 | baseMentionUrl = `${Constants.TIKTOK_ROOT}/@`; |
| 301 | break; |
| 302 | } |
| 303 | let offset = 0; |
| 304 | status.raw_text.facets.forEach((facet: APIFacet, facetIndex: number) => { |
| 305 | const [rawStart, rawEnd] = facetUtf16RangesOnPlain[facetIndex]!; |
| 306 | const [start, end] = normalizeUtf16EntityRange(text, rawStart + offset, rawEnd + offset); |
| 307 | const oldLen = end - start; |
| 308 | |
| 309 | let newFacet: string; |
| 310 | switch (facet.type) { |
| 311 | case 'bold': |
| 312 | newFacet = `<b>${text.slice(start, end)}</b>`; |
| 313 | text = text.slice(0, start) + newFacet + text.slice(end); |
| 314 | offset += newFacet.length - oldLen; |
| 315 | break; |
| 316 | case 'italic': |
| 317 | newFacet = `<i>${text.slice(start, end)}</i>`; |
| 318 | text = text.slice(0, start) + newFacet + text.slice(end); |
| 319 | offset += newFacet.length - oldLen; |
| 320 | break; |
| 321 | case 'underline': |
| 322 | newFacet = `<u>${text.slice(start, end)}</u>`; |
| 323 | text = text.slice(0, start) + newFacet + text.slice(end); |
| 324 | offset += newFacet.length - oldLen; |
| 325 | break; |
no test coverage detected