Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Commit

Permalink
feat: inline-gallerie for linked imgs
Browse files Browse the repository at this point in the history
  • Loading branch information
CanRau committed Dec 15, 2019
1 parent 2c5d986 commit 9648414
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions packages/gatsby-remark-wrap-images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ module.exports = ({ markdownAST }, pluginOptions) => {
return markdownAST
}

const containsGatsbyImage = x => /(gatsby-resp-image-)[figure|wrapper]/.test(x)

const containsOnlyWhitespace = x => /^(\\n)*\s+$/.test(x)

function modifier(node, index, parent) {
if (parent.type !== `paragraph`) return false

const whitespaceStripped = parent.children.filter(
x => !/^(\\n)*\s+$/.test(x.value) && x.type !== `image` // `type!=image` quick fix for some images not being transformed
x => !containsOnlyWhitespace(x.value)
)

const onlyContainsImages = whitespaceStripped.every(
x =>
x.type === `html` && /(gatsby-resp-image-)[figure|wrapper]/.test(x.value)
(x.type === `html` && containsGatsbyImage(x.value)) ||
(x.type === `link` && x.children.find(y => containsGatsbyImage(y.value)))
)

// Debugging help
Expand Down

0 comments on commit 9648414

Please sign in to comment.