Skip to content
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): add styles to webp img tags #20086

Merged
merged 1 commit into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,46 @@ exports[`it transforms images in markdown with query strings 1`] = `
</span>"
`;

exports[`it transforms images in markdown with the "withWebp" option 1`] = `
"<span
class=\\"gatsby-resp-image-wrapper\\"
style=\\"position: relative; display: block; margin-left: auto; margin-right: auto; max-width: 300px;\\"
>
<a
class=\\"gatsby-resp-image-link\\"
href=\\"not-a-real-dir/images/my-image.jpeg\\"
style=\\"display: block\\"
target=\\"_blank\\"
rel=\\"noopener\\"
>
<span
class=\\"gatsby-resp-image-background-image\\"
style=\\"padding-bottom: 133.33333333333331%; position: relative; bottom: 0; left: 0; background-image: url('data:image/png;base64,iVBORw'); background-size: cover; display: block;\\"
></span>
<picture>
<source
srcset=\\"not-a-real-dir/images/my-image.jpeg, not-a-real-dir/images/my-image.jpeg\\"
sizes=\\"(max-width: 650px) 100vw, 650px\\"
type=\\"undefined\\"
/>
<source
srcset=\\"not-a-real-dir/images/my-image.jpeg, not-a-real-dir/images/my-image.jpeg\\"
sizes=\\"(max-width: 650px) 100vw, 650px\\"
type=\\"undefined\\"
/>
<img
class=\\"gatsby-resp-image-image\\"
src=\\"not-a-real-dir/images/my-image.jpeg\\"
alt=\\"image\\"
title=\\"image\\"
loading=\\"lazy\\"
style=\\"width:100%;height:100%;margin:0;vertical-align:middle;position:absolute;top:0;left:0;\\"
/>
</picture>
</a>
</span>"
`;

exports[`it uses tracedSVG placeholder when enabled 1`] = `
"<span
class=\\"gatsby-resp-image-wrapper\\"
Expand Down
19 changes: 19 additions & 0 deletions packages/gatsby-remark-images/src/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ test(`it transforms images in markdown`, async () => {
expect(node.value).not.toMatch(`<html>`)
})

test(`it transforms images in markdown with the "withWebp" option`, async () => {
const imagePath = `images/my-image.jpeg`
const content = `

![image](./${imagePath})
`.trim()

const nodes = await plugin(createPluginOptions(content, imagePath), {
withWebp: true,
})

expect(nodes.length).toBe(1)

const node = nodes.pop()
expect(node.type).toBe(`html`)
expect(node.value).toMatchSnapshot()
expect(node.value).not.toMatch(`<html>`)
})

test(`it transforms multiple images in markdown`, async () => {
const imagePaths = [`images/my-image.jpeg`, `images/other-image.jpeg`]

Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-remark-images/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ module.exports = (
alt="${alt}"
title="${title}"
loading="${loading}"
style="${imageStyle}"
/>
</picture>
`.trim()
Expand Down