All Projects β†’ elboman β†’ gatsby-remark-embedded-codesandbox

elboman / gatsby-remark-embedded-codesandbox

Licence: MIT license
A Gatsby Remark plugin for embedding Codesandbox given a folder of files

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to gatsby-remark-embedded-codesandbox

gatsby-plugin-matomo
πŸ₯‚ Gatsby plugin to add Matomo (formerly Piwik) onto a site.
Stars: ✭ 56 (+80.65%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-source-stripe
Gatsby source plugin for building websites using Stripe as a data source
Stars: ✭ 71 (+129.03%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-graphcms-example
Example of Gatsby source plugin for GraphCMS
Stars: ✭ 32 (+3.23%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-transformer-remark-frontmatter
Allows querying frontmatter fields as markdown with gatsby
Stars: ✭ 13 (-58.06%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-remark-emojis
πŸš€ Processes emoji in markdown and inlines <img> tags with the corresponding base64 representation of the image.
Stars: ✭ 28 (-9.68%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-scroll-indicator
A visual indicator of page scroll on Gatsby websites
Stars: ✭ 14 (-54.84%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-attila-theme-ghost
A Gatsby theme plugin for creating blogs from headless Ghost CMS.
Stars: ✭ 16 (-48.39%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-intercom-spa
Gatsby plugin to add intercom onto a site
Stars: ✭ 23 (-25.81%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-apollo-client
πŸ“‘Inject a Shopify Apollo Client into the browser.
Stars: ✭ 20 (-35.48%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-prettier-build
prettify gatsby build output
Stars: ✭ 30 (-3.23%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-remark-numbered-footnotes
A small plugin to change named footnotes to numbered footnotes in your Gatsby pages using Markdown.
Stars: ✭ 15 (-51.61%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-dynamic-routes
Creating dynamic routes based on your environment and/or renaming existing routes
Stars: ✭ 14 (-54.84%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-remark-highlight-code
Adds stylish cards and syntax highlighting to code blocks in markdown files
Stars: ✭ 63 (+103.23%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-source-rss-feed
Gatsby source plugin for rss feed.
Stars: ✭ 24 (-22.58%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-remark-classes
Automatically add class attributes to markdown elements
Stars: ✭ 12 (-61.29%)
Mutual labels:  gatsby-plugin, gatsby-remark
gatsby-plugin-lunr
Gatsby plugin for full text search implementation based on lunr client-side index. Supports multilanguage search.
Stars: ✭ 69 (+122.58%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-plugin-disqus
πŸ’¬ A plugin for adding Disqus comments to GatsbyJS
Stars: ✭ 40 (+29.03%)
Mutual labels:  gatsbyjs, gatsby-plugin
gatsby-theme-deck-n-blog
Create a deck (with mdx-deck) and a blog post from the same MDX
Stars: ✭ 17 (-45.16%)
Mutual labels:  gatsbyjs, gatsby-plugin
Gatsby Starter Portfolio Jodie
Image-heavy photography portfolio with colorful accents & customizable pages. Includes adaptive image grids powered by CSS grid and automatic image integration into projects.
Stars: ✭ 249 (+703.23%)
Mutual labels:  gatsbyjs
vuepress-plugin-example-preview
Easily display the preview of a code snippet
Stars: ✭ 15 (-51.61%)
Mutual labels:  codesandbox

gatsby-remark-embedded-codesandbox

NPM badge Travis badge

This plugin adds support for generating embedded CodeSandbox, specifying a folder in local files to populate the contents of it. This enables example code to be stored along side of, and revisioned with, your website content.

This plugin is based on gatsby-remark-code-repls.

Getting started

To embed a CodeSandbox editor in you Markdown/remark content, simply add a link with the custom protocol pointing to the folder desired folder:

[embedded example](embedded-codesandbox://example/folder)

It will scan the folder and generate the proper html to include the editor.

Overview

For example, given the following project directory structure:

examples/
β”œβ”€β”€ hello-world-example
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ index.html
β”‚   └── index.js
β”œβ”€β”€ some-other-example
β”‚   β”œβ”€β”€ package.json
β”‚   └── index.js

These example files can be referenced via links in Markdown that get transformed to embedded editors. For example:

<!-- 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>

Note: If you are using gatsby-remark-responsive-iframe, it must appear after this plugin in your configuration or the iframe will not be transformed.

Package.json file

CodeSandbox requires a package.json file in order to work. This is useful because you can define dependencies such as react that will be included in the sandbox.

The plugin will search for the package.json file in the example folder. If not found, it will try in the parent folders up until it reaches the examples root folder.

If nothing is found it fall back to a default one:

{
  "name": "example",
  "dependencies": {}
}

Overriding options on single sandboxes

It's possible to override the global embedding options on a per-sandbox basis, by simply passing them as url query in the generating link.

[hello world example](embedded-codesandbox://hello-world-example?view=split)

The options will be merged with the global one.

How does it work?

CodeSandbox uses the same URL compression schema used by the Babel REPL to embed the local code example in a URL.

This is than passed to the (awesome) define api to generate a sandbox on the fly.

Installation

yarn add gatsby-remark-embedded-codesandbox

Usage

// In your gatsby-config.js
{
  resolve: 'gatsby-transformer-remark',
  options: {
    plugins: [
      {
        resolve: 'gatsby-remark-embedded-codesandbox',
        options: {
          // Required:

          // Example code folders are relative to this dir.
          // eg src/_examples/some-example-folder
          directory: `${__dirname}/src/_examples/`,

          // Optional:

          // Custom protocol for parsing the embedding link
          // default:
          protocol: 'embedded-codesandbox://',

          // Customise CodeSandbox embedding options:
          // https://codesandbox.io/docs/embedding#embed-options
          // default:
          embedOptions: {
            view: 'preview',
            hidenavigation: 1,
          },

          // Customise the embedding iframe given the generated url
          // default:
          getIframe: url => `<iframe src="${url}" class="embedded-codesandbox" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"></iframe>`
        }
      }
    ]
  }
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].