[gatsby-plugin-mdx] Images within <figure> nested within <p> tags are invalid
See original GitHub issueDescription
When using gatsby-plugin-mdx
with gatsby-remark-images
, images written in Markdown are being wrapped in a <p>
tag, which fails React’s DOM nesting validation because elements like <figure>
and <figcaption>
(which area generated by gatsby-remark-images
) are not valid with <p>
tags.
Steps to reproduce
Render a Markdown image:

In a Gatsby site using gatsby-plugin-mdx
and gatsby-remark-images
.
Expected result
The image would not be nested within a paragraph tag.
Actual result
The image is nested within a <p>
tag, which caused DOM validation to fail:

Environment
System:
OS: macOS 10.14.5
CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
Yarn: 1.16.0 - ~/.yarn/bin/yarn
npm: 6.9.0 - ~/.nvm/versions/node/v10.15.1/bin/npm
Languages:
Python: 2.7.10 - /usr/bin/python
Browsers:
Chrome: 75.0.3770.142
Firefox: 64.0
Safari: 12.1.1
npmPackages:
gatsby: 2.8.6 => 2.8.6
gatsby-image: 2.1.2 => 2.1.2
gatsby-plugin-favicon: 3.1.6 => 3.1.6
gatsby-plugin-feed: 2.2.3 => 2.2.3
gatsby-plugin-layout: 1.0.15 => 1.0.15
gatsby-plugin-mdx: ^1.0.7 => 1.0.7
gatsby-plugin-page-creator: 2.0.13 => 2.0.13
gatsby-plugin-react-helmet: 3.0.12 => 3.0.12
gatsby-plugin-sharp: 2.1.3 => 2.1.3
gatsby-plugin-styled-components: 3.0.7 => 3.0.7
gatsby-plugin-twitter: 2.0.13 => 2.0.13
gatsby-remark-autolink-headers: 2.0.16 => 2.0.16
gatsby-remark-copy-linked-files: ^2.1.3 => 2.1.3
gatsby-remark-external-links: 0.0.4 => 0.0.4
gatsby-remark-images: 3.1.2 => 3.1.2
gatsby-source-airtable: 2.0.8 => 2.0.8
gatsby-source-filesystem: 2.0.38 => 2.0.38
gatsby-source-github: ^0.0.2 => 0.0.2
gatsby-source-wordpress: 3.0.64 => 3.0.64
gatsby-transformer-hjson: 2.1.8 => 2.1.8
gatsby-transformer-json: 2.1.11 => 2.1.11
gatsby-transformer-remark: 2.3.12 => 2.3.12
gatsby-transformer-sharp: 2.1.21 => 2.1.21
npmGlobalPackages:
gatsby-cli: 2.6.5
Issue Analytics
- State:
- Created 4 years ago
- Reactions:17
- Comments:15 (6 by maintainers)
Top Results From Across the Web
Images getting wrapped in extra div when using combination ...
I'm using the following versions: "gatsby": "^4.21.1", "gatsby-plugin-mdx": "^4.0.0", "gatsby-remark-images": "^6.21.0", ...
Read more >Gatsby Changelog | 5.3.0
In PR #36623 we fixed this behavior and any node changes (either by changing local files or through webhook updates) will be reflected...
Read more >markdown – CSS-Tricks
To access these self-hosted files I used Eleventy's URL filters in the href and src property of the css and image tags, respectively....
Read more >gatsby-plugin-mdx
MDXProvider is a React component that allows you to replace the rendering of tags in MDX content. It does this by providing a...
Read more >Gatsby cannot query field on type query - Caritas Castellaneta
In Gatsby you DON'T capitalize the letter p. Posted on July 10, 2020 July 10, 2020 Categories How I Fixed, JavaScript Tags gatsby,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Found a workaround for the image issue, just add
remark-unwrap-images
:I guess it should be easy to adapt this plugin to embedded video and others as well.
Is there an official fix coming for this yet? I have the same problem.