Coder Social home page Coder Social logo

gatsby-remark-vega's Introduction

gatsby-remark-vega

Adds the ability to include a Vega visualization from a markdown file.

An example of an embedded Vega visualization

Usage

In your markdown, you can include vega JSON files like so:

My awesome post needs a chart:

`vega:chart.json`

Look at that chart!

The json file should sit within the same folder as the markdown file.

An example repo demonstrating the plugin is available.

Installation

The plugin can be installed with npm or yarn:

npm install gatsby-transformer-remark rehype-react gatsby-remark-vega

yarn add gatsby-transformer-remark rehype-react gatsby-remark-vega

The process for installing this plugin mimics that of gatsby-remark-component.

1.

Include the plugin in gatsby-config.js, as a plugin option for gatsby-transformer-remark:

// In your gatsby-config.js
plugins: [
  {
    resolve: `gatsby-transformer-remark`,
    options: {
      plugins: [
        `gatsby-remark-vega`,
      ],
    },
  },
];

2.

In your template, follow the same technique as showcased in gatsby-remark-component:

// within your markdown template
import rehypeReact from "rehype-react"
import Vega, { KEY as VegaKey } from "gatsby-remark-vega/dist/client";

const renderAst = new rehypeReact({
  createElement: React.createElement,
  components: {
    [vegaKey]: Vega,
  }
}).Compiler

3.

Where you render your markdown, replace:

<div dangerouslySetInnerHTML={{ __html: post.html }} />

with

<div>{renderAst(post.htmlAst)}</div>

4.

In your graphql query, make sure to select htmlAst:

...
markdownRemark(fields: { slug: { eq: $slug } }) {
 htmlAst // previously `html`
 ...
}

gatsby-remark-vega's People

Contributors

ben-dyer avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.