From e8dd69e4788cc704083f794a01ee7c17ac36aede Mon Sep 17 00:00:00 2001 From: lawvs <18554747+lawvs@users.noreply.github.com> Date: Fri, 20 Jun 2025 03:13:00 +0800 Subject: [PATCH] fix: prevent link navigation for image-only children --- apps/mobile/web-app/html-renderer/src/parser.tsx | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/apps/mobile/web-app/html-renderer/src/parser.tsx b/apps/mobile/web-app/html-renderer/src/parser.tsx index 85f555b5c..cc5c656d2 100644 --- a/apps/mobile/web-app/html-renderer/src/parser.tsx +++ b/apps/mobile/web-app/html-renderer/src/parser.tsx @@ -28,6 +28,19 @@ export const parseHtml = ( ...options, components: { a: ({ node, ...props }) => { + // Ignore link wrapper when child is an image to ensure image preview + // works instead of navigating to the link URL when clicked + // + // Check if the link contains only an image as a child + if ( + node.children && + node.children.length === 1 && + node.children[0].type === "element" && + node.children[0].tagName === "img" + ) { + // Return only the image element + return props.children + } return createElement(MarkdownLink, { ...props } as any) },