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

Feature request: Option to not use gatsby-remark-vscode for specifc code blocks #79

Open
mendes5 opened this issue Feb 19, 2020 · 1 comment
Labels
feature New feature or request good first issue Good for newcomers help wanted Would love a PR
Milestone

Comments

@mendes5
Copy link

mendes5 commented Feb 19, 2020

Currently, I need a way to tell the plugin to not render the VSCode code block in some specific blocks. Is there any way to do this?
If not we could implement something using code fence options plus a function on the gatsby-config object, something like this:

```js{useVSCode: false}
console.log('A')
plugins: [{
        resolve: `gatsby-remark-vscode`,
        options: {
           shouldRenderVSCodeForBlock: ({ useVSCode = true }) => useVSCode;
        }
      }]

I'm open to implementing this if you think it is feasible in the current architecture.

@andrewbranch
Copy link
Owner

andrewbranch commented Feb 22, 2020

Hey! This is a great idea, and I actually meant to include an option like this now that I have the plugin hooked up to GraphQL (some people might want to query for GraphQL data but not bother with rendering any HTML).

If you’re open to making a PR for this that would be awesome! I think the API should look like something this:

// types.d.ts

interface PluginOptions {
  // ...
  renderCodeBlocks?: boolean | (data: CodeFenceData) => boolean;
}

where if you pass a boolean:

plugins: [{
  resolve: `gatsby-remark-vscode`,
  options: {
    renderCodeBlocks: false
  }
}]

it applies to all code blocks, but if you pass a function:

plugins: [{
  resolve: `gatsby-remark-vscode`,
  options: {
    renderCodeBlocks: ({ parsedOptions }) => !!parsedOptions.useVSCode
  }
}]

it gets run for each block, as in your example. Only difference is the name of the option, and what gets passed as an argument should reuse the CodeFenceData type, which is:

interface CodeFenceData {
  language: string;
  markdownNode: MarkdownNode;
  codeFenceNode: any;
  parsedOptions: any;
}

so the user can access the language and the AST nodes.

@andrewbranch andrewbranch added the feature New feature or request label Feb 22, 2020
@andrewbranch andrewbranch added good first issue Good for newcomers help wanted Would love a PR labels May 4, 2020
@andrewbranch andrewbranch added this to the v3 milestone May 4, 2020
@andrewbranch andrewbranch mentioned this issue May 17, 2020
12 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request good first issue Good for newcomers help wanted Would love a PR
Projects
None yet
Development

No branches or pull requests

2 participants