diff --git a/packages/gatsby-remark-images/src/__tests__/index.js b/packages/gatsby-remark-images/src/__tests__/index.js index 0a143d4249f1a..c1f231eb1cfa0 100644 --- a/packages/gatsby-remark-images/src/__tests__/index.js +++ b/packages/gatsby-remark-images/src/__tests__/index.js @@ -144,6 +144,5 @@ test(`it leaves non-relative HTML img tags alone`, async () => { `.trim() const nodes = await plugin(createPluginOptions(content, imagePath)) - - expect(nodes.length).toBe(0) + expect(nodes[0].value).toBe(content) }) diff --git a/packages/gatsby-remark-images/src/index.js b/packages/gatsby-remark-images/src/index.js index 3dfe2dceee606..7d064851ceab5 100644 --- a/packages/gatsby-remark-images/src/index.js +++ b/packages/gatsby-remark-images/src/index.js @@ -52,6 +52,7 @@ module.exports = ( } return null }) + if (!imageNode || !imageNode.absolutePath) { return resolve() } @@ -142,15 +143,16 @@ module.exports = ( ) { const rawHTML = await generateImagesAndUpdateNode(node, resolve) - if (rawHTML != null) { + if (rawHTML) { // Replace the image node with an inline HTML node. node.type = `html` node.value = rawHTML } + return resolve(node) + } else { + // Image isn't relative so there's nothing for us to do. + return resolve() } - - // Image isn't relative so there's nothing for us to do. - return resolve() }) ) ).then(markdownImageNodes => @@ -200,13 +202,13 @@ module.exports = ( resolve ) - if (rawHTML != null) { + if (rawHTML) { // Replace the image string thisImg.replaceWith(rawHTML) + } else { + return resolve() } } - - return resolve() } // Replace the image node with an inline HTML node.