ChristopherBiscardi / gatsby-mdx

Gatsby+MDX • Transformers, CMS UI Extensions, and Ecosystem Components for ambitious projects
https://gatsby-mdx.netlify.com/
715 stars 100 forks source link

MDXProvider not using code component for inline code #371

Closed jeffwillette closed 5 years ago

jeffwillette commented 5 years ago

Describe the bug

MDXProvider used the provided component for block level code (triple backticked) but not for inline code (single backticked)

To Reproduce A link to your gatsby-mdx minimal repro and Steps to reproduce the behavior:

  1. use the kitchen sink example
  2. use components for MDXProvider
export default class RootWrapper extends React.Component {
  render() {
    const { children } = this.props;
    return (
      <MDXProvider
        components={{
          h1: ({ children, ...props }) => (
            <h1 {...props}>Provided: {children}</h1>
          ),
          pre: props => {
            console.log("pre");
            return <span style={{ backgroundColor: "green" }} {...props} />;
          },
          code: props => {
            console.log("code");
            return <span style={{ backgroundColor: "blue" }} {...props} />;
          },
          wrapper: "section"
        }}
      >
        {children}
      </MDXProvider>
    );
  }
}
  1. make one of the mdx pages have a single backticked code and triple backticked code.
  2. See that only triple backticked code uses a component and single backticked code uses a regular <code> tag

Expected behavior

I wold expect single backticked code to use a component as well

Screenshots

Screen Shot 2019-04-20 at 9 13 15 PM

johno commented 5 years ago

In order to differentiate between the code inside pre tags and inline code there's a special inlineCode node type which you'll need to use here.

Ref: https://mdxjs.com/getting-started#table-of-components

johno commented 5 years ago

🤦‍♂️ It's labeled wrong in the official docs. Fixing now.