fix: prevent link navigation for image-only children
This commit is contained in:
parent
e65a5f83a1
commit
e8dd69e478
|
|
@ -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)
|
||||
},
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue