Skip to content

Commit edfdc52

Browse files
rheinardkorfChappIO
authored andcommitted
Add 'mermaidOptions' as plugin options (#6)
1 parent 5606a6d commit edfdc52

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ Now you can use markdown:
3636

3737
```mermaid
3838
graph LR
39-
install[Install Plugin]
39+
install[Install Plugin]
4040
install --> configure[Configure Plugin]
4141
configure --> draw[Draw Fancy Diagrams]
4242
```
4343

44-
To generate:
44+
To generate:
4545

4646
![example](https://github.com/ChappIO/gatsby-remark-mermaid/raw/master/example_graph.png)
4747

@@ -53,6 +53,7 @@ To generate:
5353
| `theme` | `"default"` | Set this value to one of `"dark"`, `"neutral"`, `"forrest"`, or `"default"`. You can preview the themes in the [Live Editor](https://mermaidjs.github.io/mermaid-live-editor) |
5454
| `viewport.width` | `200` | Set this value to the desired viewport width while rendering the svg |
5555
| `viewport.height` | `200` | Set this value to the desired viewport height while rendering the svg |
56+
| `mermaidOptions` | `{}` | This object specifies the [configuration options](https://mermaidjs.github.io/#/mermaidAPI) passed to `mermaid.initialize()` |
5657

5758
### Defaults
5859

@@ -71,12 +72,15 @@ To generate:
7172
viewport: {
7273
width: 200,
7374
height: 200
75+
},
76+
mermaidOptions: {
77+
themeCSS: ".node rect { fill: cornflowerblue; }"
7478
}
75-
}
79+
}
7680
}
7781
]
7882
}
7983
}
80-
]
84+
]
8185
}
8286
```

index.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,27 @@ const path = require('path');
22
const visit = require('unist-util-visit');
33
const puppeteer = require('puppeteer');
44

5-
async function render(browser, definition, theme, viewport) {
5+
async function render(browser, definition, theme, viewport, mermaidOptions) {
66
const page = await browser.newPage();
77
page.setViewport(viewport);
88
await page.goto(`file://${path.join(__dirname, 'render.html')}`);
99
await page.addScriptTag({
1010
path: require.resolve('mermaid/dist/mermaid.min.js')
1111
});
12-
return await page.$eval('#container', (container, definition, theme) => {
12+
return await page.$eval('#container', (container, definition, theme, mermaidOptions) => {
1313
container.innerHTML = `<div class="mermaid">${definition}</div>`;
1414

1515
try {
16-
window.mermaid.initialize({theme: theme});
16+
window.mermaid.initialize({
17+
...mermaidOptions,
18+
theme
19+
});
1720
window.mermaid.init();
1821
return container.innerHTML;
1922
} catch (e) {
2023
return `${e}`
2124
}
22-
}, definition, theme);
25+
}, definition, theme, mermaidOptions);
2326
}
2427

2528
function mermaidNodes(markdownAST, language) {
@@ -37,6 +40,7 @@ module.exports = async ({markdownAST},
3740
language = 'mermaid',
3841
theme = 'default',
3942
viewport = {height: 200, width: 200},
43+
mermaidOptions = {}
4044
}) => {
4145

4246
// Check if there is a match before launching anything
@@ -51,7 +55,7 @@ module.exports = async ({markdownAST},
5155

5256
await Promise.all(nodes.map(async node => {
5357
node.type = 'html';
54-
node.value = await render(browser, node.value, theme, viewport);
58+
node.value = await render(browser, node.value, theme, viewport, mermaidOptions);
5559
}));
5660
browser.close();
5761
};

0 commit comments

Comments
 (0)