Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ stateDiagram
```
</pre>

or

<pre>
::: mermaid
stateDiagram
[*] --> First
state First {
[*] --> second
second --> [*]
}
:::
</pre>

OUTPUT

![mermaid](images/mermaid.png)
Expand Down
42 changes: 42 additions & 0 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,48 @@ function convertMarkdownToHtml(filename, type, text) {

// markdown-it-container
// https://github.com/markdown-it/markdown-it-container

const pluginKeyword = 'mermaid';
const tokenTypeInline = 'inline';
const ttContainerOpen = 'container_' + pluginKeyword + '_open';
const ttContainerClose = 'container_' + pluginKeyword + '_close';
const empty = [];

md.use(require('markdown-it-container'), pluginKeyword, {
validate: (info) => {
return info.trim() === pluginKeyword;
},

render: (tokens, idx) => {
var token = tokens[idx];

var src = '';
if (token.type === ttContainerOpen) {
for (var i = idx + 1; i < tokens.length; i++) {
var value = tokens[i]
if (value === undefined || value.type === ttContainerClose) {
break;
}
src += value.content;
if (value.block && value.nesting <= 0) {
src += '\n';
}
// Clear these out so markdown-it doesn't try to render them
value.tag = '';
value.type = tokenTypeInline;
value.content = '';
value.children = empty;
}
}

if (token.nesting === 1) {
return `<div class="${pluginKeyword}">${md.utils.escapeHtml(src)}`;
} else {
return '</div>\n';
}
}
});

md.use(require('markdown-it-container'), '', {
validate: function (name) {
return name.trim().length;
Expand Down
Binary file modified images/mermaid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions test/suite/mermaid.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,12 @@ graph TD
C -->|Two| E[iPhone]
C -->|Three| F[Car]
```

::: mermaid
graph TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[Car]
:::