Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pass plugin options to setParserPlugin #3297

Conversation

AlahmadiQ8
Copy link

reference to #3280.

Description

Currently, there is no way to pass options to remark parser plugins through setParserPlugins. For example, I wasn't able to use remark-custom-blocks since it requires to pass options.

This PR passes pluginOptions to setParserPlugins to solve this.

Example Usage

Here is an example of how gatsby-remark-custom-blocks plugin would be written.

const remarkCustomBlocks = require('remark-custom-blocks');

module.exports.setParserPlugins = ({ blocks }) => [
  [remarkCustomBlocks, blocks],
];

and in gatsby-config.js, here is how we pass required parser options.

module.exports = {
  plugins: [
    {
      resolve: 'gatsby-transformer-remark',
      options: {
        plugins: [
          {
            resolve: 'gatsby-remark-custom-blocks',
            options: {
              blocks: {
                danger: 'custom-block-danger',
                info: 'custom-block-info some-other-class',
              },
            },
          },
        ],
      },
    },
  ],
}

Testing

tbh not sure how I would add tests for this. Any feedback/examples is appreciated.

some remark plugins require options to be passed to remark. for example,
`remark.use(parserPlugin, requiredPlugin)`. This commit passes the pluginOptions
to setParserPlugins. setParserPlugins returns an array of parsers. Now array elements
can also be arrays of two elements: parser, and options.
@gatsbybot
Copy link
Collaborator

Deploy preview ready!

Built with commit 25f438f

https://deploy-preview-3297--gatsbygram.netlify.com

@gatsbybot
Copy link
Collaborator

gatsbybot commented Dec 21, 2017

Deploy preview ready!

Built with commit 3a0443f

https://deploy-preview-3297--gatsbygram.netlify.com

@KyleAMathews
Copy link
Contributor

Probably the easiest way to test this is to build a plugin (e.g. gatsby-remark-custom-block) and PR it along with an example site.

@ghost ghost assigned KyleAMathews Dec 22, 2017
@ghost ghost added the review label Dec 22, 2017
@KyleAMathews KyleAMathews merged commit eea6220 into gatsbyjs:master Dec 22, 2017
@ghost ghost removed the review label Dec 22, 2017
@KyleAMathews
Copy link
Contributor

Thanks! Great stuff!

@jlengstorf
Copy link
Contributor

Hiya @AlahmadiQ8! 👋

This is definitely late, but on behalf of the entire Gatsby community, I wanted to say thank you for being here.

Gatsby is built by awesome people like you. Let us say “thanks” in two ways:

  1. We’d like to send you some Gatsby swag. As a token of our appreciation, you can go to the Gatsby Swag Store and log in with your GitHub account to get a coupon code good for one free piece of swag. (We’ve got t-shirts and hats, plus some socks that are really razzing our berries right now.)
  2. If you’re not already part of it, we just invited you to join the Gatsby organization on GitHub. This will add you to our team of maintainers. You’ll receive an email shortly asking you to confirm. By joining the team, you’ll be able to label issues, review pull requests, and merge approved pull requests.

If you have questions, please don’t hesitate to reach out to us: tweet at @gatsbyjs and we’ll come a-runnin’.

Thanks again! 💪💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants