How to install Mermaid to render flowcharts in markdown? - github

I'm trying to render a flowchart in a markdown file using Mermaid. I have a ReadMe.md file in my GitHub repository, and I'd like to include a basic flowchart to help describe the contents. But I can't figure out how to get it to work. Would someone be able to post some more specific instructions on how to render a simple example?
In this link (https://unpkg.com/mermaid#8.0.0-rc.8/README.md), there's an example code snippet for the Mermaid installation:
```
https://unpkg.com/mermaid#7.1.0/dist/
```
I included that code, then tried to make the flowchart in the next code snippet:
```
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
But all it does is print that text out in the markdown file when I preview it.
It seems like it's possible based on the Mermaid ReadMe: https://github.com/knsv/mermaid/blob/master/README.md. But when I looked at the code it's actually a picture of the flowchart, not a rendering of code. So maybe what I'm asking isn't possible?
Would appreciate any help!

I created a Firefox & Chrome extension that wasn't available at the time of the first answer: Github + Mermaid
To use it you will need to specify mermaid as a language:
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
```
This works on:
PR and issues
Comments
Gists
(both on preview and save)
PS: I'm not sure whether it's right or not to advertise my own work here, but I feel it answers the questions.

Unfortunately, github-flavoured markdown doesn't support rendering of mermaid graphs. See this issue for more information and finding comfort in other peoples quest of this feature ;)
If your are using VS Code, you can use this extension to preview your mermaid code blocks inside markdown but note that this does not render once you put it on github. To include the chart on github you will have to render it to a file, though someone suggested somehow using the online mermaid editor to render it and retrieve an URL to a rendered version.
Actually, let me try to insert the example chart from the link on the previousely mentioned page... and, no. We get a Failed to upload image; the format is not supported-error.
So you will need to save it as an image first.

You can use mermaid-cli https://github.com/mermaidjs/mermaid.cli for generating diagrams. you can produce .svg, .png or .pdf file whatever you want.
Run following command after installing mermaid-cli
mmdc -i input.mmd -o output.png
here input.mmd is your mermaid file which contains
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
in your case.

Another solution in moving your repository to gitlab.
It natively supports mermaid in all markdown files.
Gitlab Markdown Tutorial

Feb. 2022, Markdown pages now officially support Mermaid:
(Note: Aug. 2022, GitHub wiki pages too)
See:
Include diagrams in your Markdown files with Mermaid
Mermaid is a JavaScript based diagramming and charting tool that takes Markdown-inspired text definitions and creates diagrams dynamically in the browser. Maintained by Knut Sveidqvist, it supports a bunch of different common diagram types for software projects, including flowcharts, UML, Git graphs, user journey diagrams, and even the dreaded Gantt chart.
Working with Knut and also the wider community at CommonMark, we’ve rolled out a change that will allow you to create graphs inline using Mermaid syntax:
Gist supports mermaid too.
Jan 2022, while GitHub Markdown does not yet support Mermaid, this is on the roadmap:
"Mermaid diagrams can be displayed within Markdown #372"
Just as language-specific code blocks can be added to Markdown, you'll be able to add a Mermaid diagram using a code block that specifies mermaid as its language identifier. For example:
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
The Markdown code block above uses Mermaid syntax to display this flowchart in the rendered Markdown:
And:
Another example from the Mermaid website shows how straightforward text can be used to create rich diagrams:
sequenceDiagram
autonumber
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!

Related

How to get no frame on a table in AsciiDoc on GitHub

I want to make a table in AsciiDoc on GitHub with no frame. My reading of the documentation is that this should work:
[frame="none",options="header"]
|===
| Foo | Bar
| Widget | Gadget
|===
Yet it renders with a frame:
That frame="none" setting should do it. But it doesn't. I try it without quotes and its the same. The options="header" works fine, so I know the interpreter is seeing the line in brackets and taking some action.
Is it possible that GitHub runs some version of AsciiDoc that is not full featured? If so, is there a site with the details of what does and doesn't work?
Note--this is on our internal corporate instance of GitHub Enterprise, so we may be some versions out of date, or not have some plug-in installed. Is there a special plug-in that does the trick? I don't admin the platform, so is there a way I can check versions and plug-ins in any given GitHub platform as an ordinary developer?
We use AsciiDoc pervasively as our GitHub Wiki language, so changing to another one that does tables better is not an option.
All help appreciated!
GitHub runs an official Asciidoctor to provide a nice rendering. However, they also run the generated HTML and CSS through a filtering process to prevent security issues. During that process, they strip off custom class names from a variety (if not all) elements (I don't know the exact details).
Running asciidoctor on your sample document shows a table that looks like this:
<table class="tableblock frame-none grid-all stretch">
Whereas their process results in a table that looks like:
<table>
From GitHub's perspective, those kinds of changes mean that tables look the same everywhere on the site.
If you need frameless tables, you'll probably find using GitHub Pages a lot easier because you can use custom (or asciidoctor-provided) CSS in that context.

Mermaid syntax error on trying render a diagram on Github .md file

I've followed this MermaId tutorial but when I try put into my .md file on Github an error is raised:
This works perfectely on Live editor.
Code:
```mermaid
sequenceDiagram
autonumber
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
```
Someone can help me find my error on try write it on Github
Currently, I struggle on a similar problem.
With GitHub, do you mean GitHub pages?
Could you find a solution to it?
Personally, I have a setup with Jekyll. Here is my question on how to setup mermaid correctly for jekyll.
Interestingly, I just posted your mermaid into my jekyll page and the result is:
If I put it into <div> tags with class mermaid. Setup I used was this.
And if I use the jekyll spaceship-plugin, ist renders to:
I guess, that this what it should like. Am I right?
Therefore, so far, for me mermaid works based on the spaceship plugin, but not by "natively" referencing the mermaid JavaScript. I do not know if spaceship will work with GitHub pages, however, definitely within GitHub pages (which is based on Jekyll), you may also add plugins. See documentation for further details.

Azure Devops Wiki Entity Relationship Diagram

I'm new to Azure Devops but have found items online that suggest it is possible to create Entity Relationship Diagrams in an Azure wiki page using mermaid. For example in the link below.
https://github.com/mermaid-js/mermaid/issues/1338
I can create items with mermaid code however when I use the erDiagram text and click to load diagram, I just get an "Unsupported diagram type" error. I'm not sure if this is something wrong in my text or if I need to upgrade mermaid(?). I have no clue about all this really as I'm new to it and a quick google seems to imply this is a common problem that hasn't been solved yet.
Can somebody please help?
It seems erDiagram is not presently supported by Azure DevOps Wiki's mermaid implementation. I get the same error with an erDiagram that renders fine in the Mermaid Live Editor. I've had trouble with other diagram types too.
This page, Markdown Syntax...Mermaid diagrams, indicates only three diagram types are presently supported:
Sequence diagrams
Gantt Charts
Flowcharts

How to quote code in a Mardkown GitHub Gist

In a markdown file in a Gist, how do you quote some lines of code that are in a GitHub project?
If I was writing a Gist to try and explain how something works, I might have a block of text, then quote some code. I don't want to cut and paste the code in, I just want to quote some lines of code in a GitHub project. I am sure I have seen this done, but can't find an explanation of how to do it.
For example:
This algorithm makes use of Dijkstra's topological sort algorithm:
100: Result myFancyPantsAlgorithm(Blah blah) {
101: youGetTheIdea();
102: }
It is not possible to embed GitHub code snippets from Repositories.
What you might have seen is having a gist embedded in a "normal" website which is possible because GitHub provides a script to embed gists.
The script tag is (un)fortunately not whitelisted to be used in GitHub Flavored Markdown, so it is not possible to embed a gist in markdown.
A way to get around this would be to set a gh-page up, where you are able to embed a Gist as this SO-question shows. But then you're still not referencing to any live codebase.
So the answer to your question is: this is not possible, wether by embedding code from a repository nor by taking a detour via using gists.

Can a GitHub wiki embed HTML

I would like to create a wiki page that is a preamble (standard markdown) followed by an HTML/JS code listing followed by (in a frame I suppose) the page that this code would generate.
Is this possible?
PS The code is: http://pipad.org/MathBox/slides_simple.html
Github Wikis allow you to embed HTML, but not all HTML tags are supported.
To embed supported HTML:
Edit a wiki page.
Ensure the edit mode is on "Markdown".
Type the html directly into the main content area (there's no "code" view, like you often see in tools like Wordpress).
Which tags aren't supported?
I couldn't find documentation on this, but we have a few clues:
Github wikis are built on a software tool called Gollum. We can see which tags are supported in Gollum by default here in the Gollum docs. Github may customize these defaults for their use-case, but I'll bet it's pretty similar.
I went ahead and created a test wiki here with all the major visual html elements added to it (copied from Poor Man's Styleguide). It looks like the main tags that don't display are iframe, video, audio, and all of the various form inputs (textarea, input, select, etc).