From c1c45d835fadce1184babb0d38722b4c54f60a33 Mon Sep 17 00:00:00 2001 From: Hampus Date: Thu, 24 Sep 2026 22:50:34 +0200 Subject: [PATCH] fix(app): only parse markdown in rich embeds (#2948) --- .../components/embeds/EmbedRenderUtils.ts | 4 + .../embeds/channel_embed/BlueskyEmbed.tsx | 4 +- .../embeds/channel_embed/EmbedParts.tsx | 91 ++++++++++--------- .../embeds/channel_embed/RichEmbed.tsx | 5 +- .../messaging/utils/MessageCopyTextUtils.ts | 12 ++- 5 files changed, 65 insertions(+), 51 deletions(-) diff --git a/fluxer_app/src/features/channel/components/embeds/EmbedRenderUtils.ts b/fluxer_app/src/features/channel/components/embeds/EmbedRenderUtils.ts index 6e6fad846..1be7be07e 100644 --- a/fluxer_app/src/features/channel/components/embeds/EmbedRenderUtils.ts +++ b/fluxer_app/src/features/channel/components/embeds/EmbedRenderUtils.ts @@ -20,6 +20,10 @@ export function hasRichEmbedContent(embed: RichEmbedContentFields): boolean { ); } +export function embedAllowsMarkdown(embed: Pick): boolean { + return embed.type === MessageEmbedTypes.RICH || embed.type === MessageEmbedTypes.BLUESKY; +} + type MediaOnlyEmbedFields = RichEmbedContentFields & Pick; export function isMediaOnlyEmbed(embed: MediaOnlyEmbedFields): boolean { diff --git a/fluxer_app/src/features/channel/components/embeds/channel_embed/BlueskyEmbed.tsx b/fluxer_app/src/features/channel/components/embeds/channel_embed/BlueskyEmbed.tsx index 19fd4e2eb..47538d2c5 100644 --- a/fluxer_app/src/features/channel/components/embeds/channel_embed/BlueskyEmbed.tsx +++ b/fluxer_app/src/features/channel/components/embeds/channel_embed/BlueskyEmbed.tsx @@ -205,6 +205,7 @@ export const BlueskyEmbed: FC = observer( = observer( )} = observer( )} diff --git a/fluxer_app/src/features/channel/components/embeds/channel_embed/EmbedParts.tsx b/fluxer_app/src/features/channel/components/embeds/channel_embed/EmbedParts.tsx index 505159278..3c8e4a7e1 100644 --- a/fluxer_app/src/features/channel/components/embeds/channel_embed/EmbedParts.tsx +++ b/fluxer_app/src/features/channel/components/embeds/channel_embed/EmbedParts.tsx @@ -69,47 +69,58 @@ export const EmbedAuthorComponent: FC<{author?: EmbedAuthor}> = observer(({autho ); }); -export const EmbedTitle: FC<{title?: string; url?: string; messageId?: string; channelId?: string}> = observer( - ({title, url, messageId, channelId}) => { - if (title == null || title.length === 0) return null; - const options = { - context: MarkdownContext.RESTRICTED_INLINE_REPLY, - messageId, - channelId, - disableEmojiInteractions: Boolean(url), - }; - return ( -
- {url ? ( - - - - ) : ( - - - - )} -
- ); - }, -); +export const EmbedTitle: FC<{ + title?: string; + url?: string; + markdown: boolean; + messageId?: string; + channelId?: string; +}> = observer(({title, url, markdown, messageId, channelId}) => { + if (title == null || title.length === 0) return null; + const content = markdown ? ( + + ) : ( + title + ); + return ( +
+ {url ? ( + + {content} + + ) : ( + {content} + )} +
+ ); +}); export const EmbedDescription: FC<{ messageId?: string; channelId?: string; description?: string; -}> = observer(({messageId, channelId, description}) => { + markdown: boolean; +}> = observer(({messageId, channelId, description, markdown}) => { if (!description) return null; return (
- + {markdown ? ( + + ) : ( + description + )}
); }); @@ -182,9 +193,7 @@ export const EmbedFields: FC<{fields?: ReadonlyArray; messageId?: st export const EmbedFooterComponent: FC<{ timestamp?: Date; footer?: EmbedFooter; - messageId?: string; - channelId?: string; -}> = observer(({timestamp, footer, messageId, channelId}) => { +}> = observer(({timestamp, footer}) => { const {i18n} = useLingui(); const allowIconMotion = useShouldAnimate({kind: 'gif'}); const formattedTimestamp = timestamp ? DateUtils.getRelativeDateString(timestamp, i18n) : undefined; @@ -206,13 +215,7 @@ export const EmbedFooterComponent: FC<{ /> )}
- {footer?.text && ( - - )} + {footer?.text} {formattedTimestamp && ( <> {footer?.text && ( diff --git a/fluxer_app/src/features/channel/components/embeds/channel_embed/RichEmbed.tsx b/fluxer_app/src/features/channel/components/embeds/channel_embed/RichEmbed.tsx index 2a3f8f45c..8867d2827 100644 --- a/fluxer_app/src/features/channel/components/embeds/channel_embed/RichEmbed.tsx +++ b/fluxer_app/src/features/channel/components/embeds/channel_embed/RichEmbed.tsx @@ -25,6 +25,7 @@ import { } from '@app/features/channel/components/embeds/channel_embed/EmbedParts'; import { EMBED_TEXT_OUTER_WIDTH, + embedAllowsMarkdown, formatResponsiveEmbedWidth, } from '@app/features/channel/components/embeds/EmbedRenderUtils'; import markupStyles from '@app/features/theme/styles/Markup.module.css'; @@ -83,6 +84,7 @@ export const RichEmbed: FC = observer( = observer( {!isYouTubeEmbed && ( = observer( )} diff --git a/fluxer_app/src/features/messaging/utils/MessageCopyTextUtils.ts b/fluxer_app/src/features/messaging/utils/MessageCopyTextUtils.ts index 3d8bc62be..aaa92f309 100644 --- a/fluxer_app/src/features/messaging/utils/MessageCopyTextUtils.ts +++ b/fluxer_app/src/features/messaging/utils/MessageCopyTextUtils.ts @@ -1,5 +1,6 @@ // SPDX-License-Identifier: AGPL-3.0-or-later +import {embedAllowsMarkdown} from '@app/features/channel/components/embeds/EmbedRenderUtils'; import {MarkdownContext} from '@app/features/messaging/components/markdown/renderers/RendererTypes'; import type {Message} from '@app/features/messaging/models/MessagingMessage'; import {getParserFlagsForContext} from '@app/features/messaging/utils/markdown/MarkdownParserFlags'; @@ -193,8 +194,13 @@ export function buildMessageEmbedCopyText(embed: MessageEmbed, options: EmbedCop const blocks: Array = []; appendCopyBlock(blocks, embed.provider?.name); appendCopyBlock(blocks, embed.author?.name); - appendCopyBlock(blocks, renderMarkdownCopyText(embed.title, EMBED_INLINE_COPY_PARSER_FLAGS, options)); - appendCopyBlock(blocks, renderMarkdownCopyText(embed.description, EMBED_DESCRIPTION_COPY_PARSER_FLAGS, options)); + if (embedAllowsMarkdown(embed)) { + appendCopyBlock(blocks, renderMarkdownCopyText(embed.title, EMBED_INLINE_COPY_PARSER_FLAGS, options)); + appendCopyBlock(blocks, renderMarkdownCopyText(embed.description, EMBED_DESCRIPTION_COPY_PARSER_FLAGS, options)); + } else { + appendCopyBlock(blocks, embed.title); + appendCopyBlock(blocks, embed.description); + } if (options.includeFields !== false && embed.type !== MessageEmbedTypes.BLUESKY) { for (const field of embed.fields ?? []) { const fieldName = renderMarkdownCopyText(field.name, EMBED_INLINE_COPY_PARSER_FLAGS, options); @@ -202,7 +208,7 @@ export function buildMessageEmbedCopyText(embed: MessageEmbed, options: EmbedCop appendCopyBlock(blocks, joinCopyBlocks([fieldName, fieldValue])); } } - appendCopyBlock(blocks, renderMarkdownCopyText(embed.footer?.text, EMBED_INLINE_COPY_PARSER_FLAGS, options)); + appendCopyBlock(blocks, embed.footer?.text); appendCopyBlock(blocks, getFormattedEmbedTimestamp(embed.timestamp)); appendCopyBlock(blocks, embed.image?.description); appendCopyBlock(blocks, embed.thumbnail?.description);