hashicorp/next-mdx-enhanced

Direction on CodeSandbox Embed Remark Plugin

karlhorky opened this issue · 3 comments

Hi there! First of all, thanks for this project! It seems like it adds some nice features to the default MDX plugin.

I'm currently trying to move to Next.js from Gatsby, and one thing that's holding me back is the excellent elboman/gatsby-remark-embedded-codesandbox.

My use case is generating sandboxes on CodeSandbox using the contents of example folders locally in my project. These are embedded using link syntax in Markdown:

<!-- before -->

[hello world example](embedded-codesandbox://hello-world-example)

<!-- after -->

<iframe src="https://codesandbox.io/api/v1/sandboxes/define?embed=1&parameters=N4IgZglgNgpgziAXKADgQwMYGs0HMYB0AVnAPYB2SoGFALjObVSOWgLYxIgwAe7KsEAF8hAGhARyAE14EAFrTZRmNRgyaIQAHgVKAfFoBGpKQE8DAemNnLuqHuHjJMnsQTIQq-oy6q4tAAIwUlIAgF4AgB0QQzQAJ2iAbmERIA&query=hidenavigation%3D1%26view%3Dpreview" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;\\" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>

I'm considering how to solve this in the best way, and I wanted to ask if you would have any direction on this. I suppose taking the Gatsby Remark plugin code and creating a vanilla Remark plugin by removing the Gatsby-specific bits could work...? But maybe there are Remark plugin limitations that I'm not aware of.

If that did work like this, then I suppose I could use this with your remarkPlugins option.

If this is too far from the topic of this package or if you cannot help, I totally understand! Just wanted to ping in case.

I've also opened elboman/gatsby-remark-embedded-codesandbox#20, to explore how to create this plugin.

Hey @karlhorky - I would recommend writing this as a pure remark plugin as you suggested, it should be fairly straightforward to implement. You can then pass the plugin in through the remarkPlugins option. At my company we use several custom remark plugins this same way in production and it's working quite nicely.

I'm going to close this issue as it's more of a discussion about direction on a separate project than an issue, but please don't take that as a bad thing, and I welcome continued discussion in this thread as well!