Skip to content

Commit

Permalink
Fix rendering markdown links with text as images
Browse files Browse the repository at this point in the history
  • Loading branch information
ekzyis committed Oct 3, 2023
1 parent 11c3cfa commit 9cdbc24
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ export default memo(function Text ({ nofollow, imgproxyUrls, children, tab, ...o
return <>{children}</>
}

// If [text](url) was parsed as <a> and text is not empty, we don't render it as an image
// since it was probably a concious choice to include text.
const text = children?.[0]
if (!!text && !/^https?:\/\//.test(text)) {
return <a target='_blank' rel={`noreferrer ${nofollow ? 'nofollow' : ''} noopener`} href={href}>{children[0]}</a>
}

// assume the link is an image which will fallback to link if it's not
return <Img src={href} nofollow={nofollow} {...props}>{children}</Img>
},
Expand Down

0 comments on commit 9cdbc24

Please sign in to comment.