MCPcopy Create free account
hub / github.com/FxEmbed/FxEmbed / generateCommunityNote

Function generateCommunityNote

src/render/instantview.ts:291–325  ·  view source on GitHub ↗
(status: APITwitterStatus)

Source from the content-addressed store, hash-verified

289};
290
291const generateCommunityNote = (status: APITwitterStatus): string => {
292 const note = status.community_note;
293 if (!note) {
294 return '';
295 }
296
297 let lastToIndex = 0;
298 let result = '';
299
300 if ('facets' in note) {
301 const sorted = [...note.facets].sort((a, b) => a.indices[0] - b.indices[0]);
302 for (const facet of sorted) {
303 if (facet.type !== 'url') {
304 continue;
305 }
306 const [fromIndex, toIndex] = facet.indices;
307 const href = facet.replacement ?? '';
308 const label = facet.display ?? note.text.substring(fromIndex, toIndex);
309 result += note.text.substring(lastToIndex, fromIndex);
310 result += `<a href="${href}">${label}</a>`;
311 lastToIndex = toIndex;
312 }
313 }
314
315 result += note.text.substring(lastToIndex);
316
317 return `<table>
318 <thead>
319 <th><b>${i18next.t('ivCommunityNoteHeader')}</b></th>
320 </thead>
321 <tbody>
322 <th>${result.replace(/\n/g, '\n<br>')}</th>
323 </tbody>
324 </table>`;
325};
326
327const generateStatus = (
328 status: APIStatus | APIStatusTombstone,

Callers 1

generateStatusFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected