Clean-up Extraneous Paragraph Tags and Table Whitespace in MDX on GatsbyJS

MDX on GatsbyJS nests JSX components in paragraph tags which can produce invalid HTML so you end up with invalid HTML resembling:

Loading...
<p> <div class="jsx-component">...</div> </p>

When using Markdown tables, it can also leave extra whitespace that can produce HTML syntax warnings. Not showstopping, but annoying all the same.

Create this plugin in your ./plugins directory and add it to the end of your gatsbyRemarkPlugins in gatsby-config.js.

Published October 9, 2021