Giter Club home page Giter Club logo

remark-graphviz's Introduction

remark-graphviz

NPM Travis CI MIT License

Replaces graphs defined in dot with rendered SVGs.

Installation

$ npm install remark-graphviz

Usage

Graphs defined using dot can be referenced using a dot: title which will generate an SVG image.

[Link to a Graph](test/fixtures/assets/example.dot "dot:")
![Embed image of graph](test/fixtures/assets/example.dot "dot:")

Alternatively, graphs can be generated inline, by using dot (or circo) as the language identifier for a fenced code block.

```dot
digraph graphname {
  a -> b;
  b -> c;
  a -> c;
}
```

See this project's fixtures for more examples.

Example

Given a file, example.md, which contains the following Markdown:

# dot code block

```dot
digraph graphname {
  a -> b;
  b -> c;
  a -> c;
}
```

Using remark like follows:

var vfile = require('to-vfile');
var remark = require('remark');
var graphviz = require('remark-graphviz');

var example = vfile.readSync('example.md');

remark()
  .use(graphviz)
  .process(example, function (err, file) {
    if (err) throw err;

    console.log(String(file))
  });

Will result in an SVG being written relative to example.md, and the Markdown being transformed to:

# dot code block

![](./6b03e143dc2a47a93496133d692c44d5ec012b57.svg "`dot` image")

To change where the SVG's are written, set data.destinationFilePath on the vFile. This following shows how you could process a file from one directory and output the transformed file to another:

var vfile = require('to-vfile');
var remark = require('remark');
var graphviz = require('remark-graphviz');

var example = vfile.readSync('example.md');
example.data = {
  destinationFilePath: 'out/example.md'
};

remark()
  .use(graphviz)
  .process(example, function (err, file) {
    if (err) throw err;

    vfile.writeSync({ path: file.data.destinationFilePath });
  });

Both example.md and the generated SVG will reside in the /out directory.

remark-graphviz's People

Contributors

brendo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

Forkers

mwlynch phryneas

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.