fix: prevent link navigation for image-only children

This commit is contained in:
lawvs 2025-06-20 03:13:00 +08:00
parent e65a5f83a1
commit e8dd69e478
1 changed files with 13 additions and 0 deletions

View File

@ -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)
},