From 8b398f4630d994aa31bfb7d4253b07d5c29d212c Mon Sep 17 00:00:00 2001 From: AJ Schmidt Date: Mon, 24 Jun 2019 10:52:29 -0400 Subject: [PATCH] fix(gatsby-remark-images): remove clickable whitespace around image when linking (#11528) * update remark-images links * Fix snapshots --- .../src/__tests__/__snapshots__/index.js.snap | 316 +++++++++--------- packages/gatsby-remark-images/src/index.js | 26 +- 2 files changed, 173 insertions(+), 169 deletions(-) diff --git a/packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap b/packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap index 8d475ede9cff4..b9e98d952adff 100644 --- a/packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap +++ b/packages/gatsby-remark-images/src/__tests__/__snapshots__/index.js.snap @@ -2,14 +2,14 @@ exports[`it handles goofy nesting properly 1`] = ` " - - + + \\"test\\" - " + " `; exports[`it leaves images that are already linked alone 1`] = ` " - - + + \\"img\\" - " + " `; exports[`it leaves linked HTML img tags alone 1`] = ` " - - \\"this - + + \\"this + " `; exports[`it leaves single-line linked HTML img tags alone 1`] = ` " - - \\"this - " + + \\"this + " `; exports[`it transforms HTML img tags 1`] = ` -" - +" + - \\"my - - " + \\"my + + " `; exports[`it transforms HTML img tags with query strings 1`] = ` -" - +" + - \\"my - - " + \\"my + + " `; exports[`it transforms image references in markdown 1`] = ` -" + - - + \\"alt - - " + + " `; exports[`it transforms images in markdown 1`] = ` -" + - - + \\"image\\" - - " + + " `; exports[`it transforms images in markdown with query strings 1`] = ` -" + - - + \\"image\\" - - " + + " `; exports[`it uses tracedSVG placeholder when enabled 1`] = ` -" + - - + \\"image\\" - - " + + " `; exports[`showCaptions display alt as caption if specified first in showCaptions array 1`] = ` "
- + - - + \\"some - +
some alt
" `; exports[`showCaptions display alt as caption if specified in showCaptions array 1`] = ` "
- + - - + \\"some - +
some alt
" `; exports[`showCaptions display alt as caption if title was not found and showCaptions === true 1`] = ` "
- + - - + \\"some - +
some alt
" `; exports[`showCaptions display title as caption if specified first in showCaptions array 1`] = ` "
- + - - + \\"some - +
some title
" `; exports[`showCaptions display title as caption if specified in showCaptions array 1`] = ` "
- + - - + \\"some - +
some title
" `; exports[`showCaptions display title as caption when showCaptions === true 1`] = ` "
- + - - + \\"some - +
some title
" `; exports[`showCaptions fallback to alt as caption if specified second in showCaptions array 1`] = ` "
- + - - + \\"some - +
some alt
" `; exports[`showCaptions fallback to title as caption if specified second in showCaptions array 1`] = ` "
- + - - + \\"my - +
some title
" `; diff --git a/packages/gatsby-remark-images/src/index.js b/packages/gatsby-remark-images/src/index.js index 15cb2537fd6cd..037f95a88fc0d 100644 --- a/packages/gatsby-remark-images/src/index.js +++ b/packages/gatsby-remark-images/src/index.js @@ -274,17 +274,10 @@ module.exports = ( let rawHTML = ` - - ${imageTag} - + class="${imageBackgroundClass}" + style="padding-bottom: ${ratio}; position: relative; bottom: 0; left: 0; background-image: url('${placeholderImageData}'); background-size: cover; display: block;" + > + ${imageTag} `.trim() // Make linking to original image optional. @@ -302,6 +295,17 @@ module.exports = ( `.trim() } + rawHTML = ` + + ${rawHTML} + + `.trim() + // Wrap in figure and use title as caption if (imageCaption) { rawHTML = `