Skip to content

Commit

Permalink
Fix images disappearing from rendered markdown files
Browse files Browse the repository at this point in the history
Fixes #3608
  • Loading branch information
kripod committed Jan 19, 2018
1 parent 53f66a4 commit 00c7a01
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions packages/gatsby-remark-images/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ module.exports = (
class="gatsby-resp-image-wrapper"
style="position: relative; display: block; ${
options.wrapperStyle
}; max-width: ${presentationWidth}px; margin-left: auto; margin-right: auto;"
}; max-width: ${presentationWidth}px; margin-left: auto; margin-right: auto;"
>
<span
class="gatsby-resp-image-background-image"
style="padding-bottom: ${ratio}; position: relative; bottom: 0; left: 0; background-image: url('${
responsiveSizesResult.base64
}'); background-size: cover; display: block;"
}'); background-size: cover; display: block;"
>
<img
class="gatsby-resp-image-image"
style="width: 100%; height: 100%; margin: 0; vertical-align: middle; position: absolute; top: 0; left: 0; box-shadow: inset 0px 0px 0px 400px ${
options.backgroundColor
};"
options.backgroundColor
};"
alt="${node.alt ? node.alt : defaultAlt}"
title="${node.title ? node.title : ``}"
src="${fallbackSrc}"
Expand Down Expand Up @@ -141,14 +141,16 @@ module.exports = (
fileType !== `svg`
) {
const rawHTML = await generateImagesAndUpdateNode(node, resolve)
// 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()

if (rawHTML != null) {
// Replace the image node with an inline HTML node.
node.type = `html`
node.value = rawHTML
}
}

// Image isn't relative so there's nothing for us to do.
return resolve()
})
)
).then(markdownImageNodes =>
Expand Down Expand Up @@ -197,11 +199,14 @@ module.exports = (
formattedImgTag,
resolve
)
// Replace the image string
thisImg.replaceWith(rawHTML)
} else {
return resolve()

if (rawHTML != null) {
// Replace the image string
thisImg.replaceWith(rawHTML)
}
}

return resolve()
}

// Replace the image node with an inline HTML node.
Expand All @@ -213,6 +218,6 @@ module.exports = (
)
).then(htmlImageNodes =>
markdownImageNodes.concat(htmlImageNodes).filter(node => !!node)
)
)
)
}

0 comments on commit 00c7a01

Please sign in to comment.