From ca5aee10f2663709ad2a9b5fa52327a4d49b0f43 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Mon, 2 Mar 2026 13:46:56 -0500 Subject: [PATCH] feat: include alt text in image/attachment property federating out closes #13124 --- src/activitypub/mocks.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/activitypub/mocks.js b/src/activitypub/mocks.js index 6eef6d2665..de9284ddf2 100644 --- a/src/activitypub/mocks.js +++ b/src/activitypub/mocks.js @@ -743,6 +743,28 @@ Mocks.notes.public = async (post) => { } attachment = normalizeAttachment(attachment); + + // Retrieve alt text from content (if found) + if (source?.content && source?.mediaType === 'text/markdown') { + const mdImageRegex = /!\[(.+?)\]\(([^\\)]+)\)/g; + const found = new Map(); + let current = mdImageRegex.exec(source.content); + while (current !== null) { + const [, alt, src] = current; + found.set(src.replace('-resized', ''), alt); + current = mdImageRegex.exec(source.content); + } + + attachment = attachment.map((attachment) => { + if (found.has(attachment.url)) { + attachment.name = found.get(attachment.url); + } + + return attachment; + }); + } + + // 'image' seems to be used as the preview image in lemmy/piefed, use the first one. const image = attachment.filter(entry => entry.type === 'Image')?.shift(); // let preview; let summary = null;