-
Notifications
You must be signed in to change notification settings - Fork 100
gatsby-remark-* plugin support #10
Comments
Would also be interested in that so that people can use my plugin with their React components: |
haven't try with
import pic from './pic.jpg'
<img src={pic} alt='12' />
so as a workaround I use // layout
export const ImageContext = React.createContext('images');
import { ImageContext } from './Layout'
const Mdxayout = (props) => {
const { data, children } = props
return (
<ImageContext.Provider value={data}>
{children}
</ImageContext.Provider>
)
// mdx
import Layout from '../components/Layout'
import Img from 'gatsby-image'
export default Layout
export const query = graphql`
query CollectionPic {
file(relativePath: { eq: "pic.jpg" }) {
childImageSharp{
fluid(maxWidth: 320) {
...GatsbyImageSharpFluid
}
}
}
}
`
<ImageContext.Consumer>
{data => {
return <Img fluid={data.file.childImageSharp.fluid} alt='pic-alt' />
}}
</ImageContext.Consumer> |
MDX works out of the box with remark plugins, I think the best strategy would be to try and write the gatsby remark plugins as plain remark plugins? I know that doesn't really work, but maybe there is a way to do both, e.g. wrap in gatsby plugin for the gatsby specific work and move the remark ast stuff to proper plugins? In that case both gatsby-remark, and gatsby-mdx could implement the same convention for consuming sub-plugins? Or maybe gatsby-mdx could be handed directly to the gatsby remark-plugin |
@jquense there are a few classes of plugins right now.
{
...
mdPlugins: [],
hastPlugins: []
...
}
// extend-node-type
options.mdPlugins.push(parserPlugin);
TBD on how many plugins we can support by passing in the AST at the right stage in the pipeline, but that's the current approach I'm taking for full gatsby-remark-* support. |
nice breakdown 👍 its mainly 3 i think we can consolidate or make compatible i think. Ideally (i think we'd agree) i't be great if all the gatsby remark prism, image, etc plugins worked interchangably between On top of that it may make sense to build hooks into the remark transformer so that mdx can be a child plugin, or maybe just a common set of conventions so all the existing child remark gatsby plugins (prism, images, etc) could be added to gatsby-mdx same as they are to the transformer |
I worked out support for item 4 today in #68 on the stream today by basically using a closure to encapsulate the scope and apply a new programmatically created remark plugin for each gatsby-remark plugin. The problems are no longer the differing interfaces, but rather the interface between the plugins and the mdx parser. For example, gatsby-remark-prismjs outputs html into the tree but mdx isn't escaping it at that point in the pipeline so we need to apply a new remark plugin to convert html into jsx for html nodes. (otherwise mdx will choke on things like |
Basically, now we just need to work out the kinks and see what plugins cause what edge cases |
gatsby-remark-* plugin support was released in 0.1.1. Anyone who has custom plugins or uses gatsby-remark-* plugins can test it out by following the config shown in the custom-remark-plugins example. As we discover edge cases for plugins, they should go into their own issues so we can knock them down one by one. I expect that there will be issues as we get through the long-tail of plugin compatibility and I know of at least one instance of the autolink header misapplying styles because it uses We also need to follow up with mdx-js and push some parsing changes upstream so we can get them out of gatsby-mdx and into core mdx. |
@youngboy's method (#10 (comment)) no longer seems to work (v0.1.4). import pic from './pic.jpg'
<img src={pic} alt='12' /> Has this method been deprecated in favor of using gatsby-remark-images? |
@alexchantastic Assuming you set up the proper webpack loader importing files like that should still work since it doesn't really depend on mdx, but you can use the gatsby-mdx docs to set up gatsby-remark-images. |
@ChristopherBiscardi thanks for the prompt reply. I did a little bit more digging and this might be an issue with mdx-js itself in that inline JSX doesn't seem to work properly. This: import image from './my-image.png;
<img src={image} />
<img src={`http://www.my-website.com/my-image.png`} />
<img src="http://www.my-website.com/my-image.png" /> Outputs this: <img src="{image}">
<img src="{`http://www.my-website.com/my-image.png`}">
<img src="http://www.my-website.com/my-image.png"> These seem to be the relevant issues in mdx-js: mdx-js/mdx#246 mdx-js/mdx#222 |
It'd be awesome if it could support gatsby-remark-* plugins so it instantly has image support, etc. Not 100% sure if possible so if not, reimplement a similar API.
The text was updated successfully, but these errors were encountered: