Replies: 1 comment 1 reply
-
You could create custom components that styles/wrap text and image. Then import them and use as shortcode/components Example: // in Image.js
// ...do your styling and etc
const Image = ({ children, props }) => {
return (
<figure>
{children}
<figcaption>{props.caption}</figcaption>
</figure>
)
}
// in PostLayout.js
import Image from './components/Image';
import { MDXProvider } from '@mdx-js/react'
const components = {
img: Image
// ...other custom components for mdx
};
export default function PostLayout({ children }) {
return (
<MDXProvider components={components}>
{children}
</MDXProvider>
)
}
// in some-post.mdx
## My Post Title
<Image caption="some caption">

</Image> Ref-1: https://mdxjs.com/docs/using-mdx/#mdx-provider |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
This may be a really basic question on MDX but struggling to find a sample or what terms to Google.
I am using MDX and the FileAPI to create pages for case studies. I'd like to create some custom layout components to drop in shortcodes that place images and text in styled layouts.
I am stuck on two things:
How or can I pass in markdown content as children, and render it as normal? I'm trying not to switch to HTML formatting in markdown.
With the new Gatsby Image Plugin how should you reference the image in the component when using gatsby-remark-images?
Example code snippet of what I am using on my MDX pages.
Beta Was this translation helpful? Give feedback.
All reactions