-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gatsby-remark-images): don’t add links if image is already linked #6982
Conversation
fixes gatsbyjs#6980 Co-authored-by: @pieh
Deploy preview for using-postcss-sass failed. Built with commit b610710 https://app.netlify.com/sites/using-postcss-sass/deploys/5b65025067610c74d2ed4d3a |
Deploy preview for using-drupal ready! Built with commit b610710 |
Deploy preview for gatsbygram ready! Built with commit b610710 |
const inLink = ancestors.some(ancestor => ancestor.type === `link`) | ||
if (!inLink) { | ||
markdownImageNodes.push(node) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is broken. We still need to fix the relative path, which I'm pretty sure @pieh told me to do and I just... didn't.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to process images in both cases (when it's inside link and when it's not) - difference should be whether we wrap image in link here - https://github.com/jlengstorf/gatsby/blob/af209f9215d8cd9c5ec2f3fda1cbdae1ec40027d/packages/gatsby-remark-images/src/index.js#L175-L188
@@ -240,6 +248,11 @@ module.exports = ( | |||
|
|||
let imageRefs = [] | |||
$(`img`).each(function() { | |||
// Make sure we don’t override already-linked images | |||
if ($(this).closest(`a`).length > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately this won't work because a
won't be in same html
ast node - html
nodes will contain single html tags from my research so <a href="http://example.com"><img src="./some-image.jpg"/></a>
will have html
ast node for a
and children of that will be separate html
ast node for img
. I think this will need to be handled similiarly as checking if markdown image is in markdown link.
Following trend of nonsense examples we had yesterday: ;)
or
with mix of markdown and html? I would say this is not in scope for this PR - I think we just need to handle markdown image in markdown link here. |
Alright — I think I cracked this. Added a check for both
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
…gatsbyjs#6982) * fix(gatsby-remark-images): don’t add links if image is already linked fixes gatsbyjs#6980 Co-authored-by: @pieh * fix: handle weird nesting and mixed MD/HTML * fix: remove bad check for parent links
Thanks for the help, @pieh!
fixes #6980