iamskok / gatsby-remark-code-buttons

Buttons for code snippets 🔘
https://gatsby-dev-blog-starter.netlify.com/blog/building-your-first-react-app
19 stars 9 forks source link

Gatsby build fails if markdown contains a code block within a list item #14

Closed adamjcooper closed 3 years ago

adamjcooper commented 3 years ago

When building markdown which contains a code block which is part of a list item, like this:

1. First install this thing.
2. Then do this:

    ```js
    const thing = require('installed-thing')
  1. Then start the app.

This plugin will currently cause the gatsby build to fail with:

TypeError: Cannot read property 'replace' of undefined

This is happening because the current implementation of the visit handler assumes that every code block is a top-level node in the AST. The problem can be fixed by updating the visit handler to take a third parent argument and then, within the implementation of the handler, use parent.children instead of markdownAST.children.