Giter VIP home page Giter VIP logo

mermrender's Introduction

๐Ÿงœโ€โ™€๏ธ Mermrender

RESTful rendering pipeline for generating sequence and UML diagrams using Mermaid to embed in Github readmes, Markdown docs and more! Mermrender uses Mermaid.JS and Mermaid CLI under the hood.

Feel free to contribute by making a pull request!

Maintainer: [email protected]

Mermaid Credit: https://mermaidjs.github.io/

Run Mermrender in Gitpod, a free online dev environment for GitHub:

Open in Gitpod

Hit the API! (Demo)

https://3000-cebcfedc-d281-4f38-b13a-cc6312da177b.ws-us0.gitpod.io/diagram/2VxdWVuY2VEaWF

img

Setup in VSCode

Check out this awesome guide for setting up diagram rendering within VSCode: https://quintussential.com/archive/2017/12/10/Diagraming-with-Mermaid/

Motivation

Github doesn't support rendering Mermaid diagrams in their Markdown editor. Mermaid is a powerful tool that uses a well-defined schema to then interpret diagrams into an SVG. The idea of this tool is to allow embedding images dynamically via a REST endpoint to add UML/Sequence diagrams into your documentation/readmes/markdown files easily, whether the editor supports Mermaid or not.

Demo

demo

Usage

1) Generate the diagram code with Mermaid OR PlantUML

sequenceDiagram
    participant A as Alice
    participant J as John
    A->>J: Hello John, how are you?
    J->>A: Great!

or

@startuml
object Object01
object Object02
object Object03
object Object04
object Object05
object Object06
object Object07
object Object08

Object01 <|-- Object02
Object03 *-- Object04
Object05 o-- "4" Object06
Object07 .. Object08 : some labels
@enduml

You can edit and render them live on this website: https://mermaidjs.github.io/mermaid-live-editor/

2) Escape the diagram to encode it

Next, you need to run it through an escaper like the following: https://www.freeformatter.com/java-dotnet-escape.html#ad-output

3) Generate the image link to embed

Send a POST request to http://localhost:3000/encode/plantuml or http://localhost:3000/encode/mermaid depending on the type with a diagram key in the body with the above escaped diagram:

Example Body:

{
  "diagram": "sequenceDiagram\r\n    participant Alice\r\n    participant Bob\r\n    Alice->>John: Hello John, how are you?\r\n    loop Healthcheck\r\n        John->>John: Fight against hypochondria\r\n    end\r\n    Note right of John: Rational thoughts <br/>prevail...\r\n    John-->>Alice: Great!\r\n    John->>Bob: How about you?\r\n    Bob-->>John: Jolly good!"
}

This will generate a respose:

{
  "embed_link": "http://localhost:3000/diagram/2VxdWVuY2VEaWF"
}

You can embed the following embed_link by using the following syntax:

Markdown

![alt_caption](http://localhost:3000/diagram/2VxdWVuY2VEaWF)

HTML

<img src="http://localhost:3000/diagram/2VxdWVuY2VEaWF"/>

BBCode (Forums)

[img]http://localhost:3000/diagram/2VxdWVuY2VEaWF[/img]

Additional Options

Add the following optional query parameters to add custom dimensions to your images:

(Not yet implemented)

How To Run

  1. npm i to install dependencies
  2. node index.js
  3. sudo npm install -g node-plantuml
  4. sudo npm install -g mermaid.cli

or run Mermrender in Gitpod, a free online dev environment for GitHub:

Open in Gitpod

mermrender's People

Contributors

jankeromnes avatar schachte avatar

Stargazers

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

mermrender's Issues

Add PlantUML

Great work! Would you be interested in adding capabilities for PlantUML? The syntax is very similar. If so, I'll donate $50 to you or your favorite charity.

Demo diagrams with syntax examples -- see the final one for an example document that I want to render for my team's devops pipeline:

https://github.com/joelparkerhenderson/demo_plantuml/

Create basic UI to abstract further away from API

I think it would be nice to just dump the mmd data into a textbox and have it spit out the markdown to embed instantly. Having it as part of the UI would make it a lot more user-friendly and quicker to embed.

Add image update and unique hashing support

Right now, image hashes are unique and therefore you're currently unable to update an image, but keep the same URL. This defeats a lot of benefits from having DaaS ( Diagrams as a service) because then you have to update 2 areas of code instead of one.

Proposition:
Realistically need to have authentication to do this correctly. For simplicity I think it would work to give the user capability to add their own client id, their own image name and then we can hash serverside with 3 tokens.

The downside is that collisions can still occur, which could theoretically cause some really odd behavior..

Potential solution to remediate collisions (prior to integrating auth) is to add a client id generate to get a more random hash.

All in all, without auth, the UX becomes poor. Something worth iterating on.

Add Dockerfile and docker-compose.yml in root

Need to have everything dockerized to allow quicker iterations without worrying about dependencies. Ideally should use nodemon for realtime updates and be mounted from the host directly.

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.