Skip to content

Commit 5606a6d

Browse files
authored
Configurable viewport (#4)
1 parent 2103fb8 commit 5606a6d

File tree

4 files changed

+18
-11
lines changed

4 files changed

+18
-11
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,12 @@ To generate:
4747

4848
## Options
4949

50-
| Name | Default | Description |
51-
| --- | --- | --- |
52-
| `language` | `"mermaid"` | Set this value to the identifier which will replace the code block. If you set it to `"graph"` then you can create graphs using ` ```graph ...`. |
53-
| `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) |
50+
| Name | Default | Description |
51+
| --- | --- | --- |
52+
| `language` | `"mermaid"` | Set this value to the identifier which will replace the code block. If you set it to `"graph"` then you can create graphs using ` ```graph ...`. |
53+
| `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) |
54+
| `viewport.width` | `200` | Set this value to the desired viewport width while rendering the svg |
55+
| `viewport.height` | `200` | Set this value to the desired viewport height while rendering the svg |
5456

5557
### Defaults
5658

@@ -65,7 +67,11 @@ To generate:
6567
resolve: 'gatsby-remark-mermaid',
6668
options: {
6769
language: 'mermaid',
68-
theme: 'default'
70+
theme: 'default',
71+
viewport: {
72+
width: 200,
73+
height: 200
74+
}
6975
}
7076
}
7177
]

index.js

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

5-
async function render(browser, definition, theme) {
5+
async function render(browser, definition, theme, viewport) {
66
const page = await browser.newPage();
7-
page.setViewport({width: 200, height: 200});
7+
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')
@@ -35,7 +35,8 @@ function mermaidNodes(markdownAST, language) {
3535
module.exports = async ({markdownAST},
3636
{
3737
language = 'mermaid',
38-
theme = 'default'
38+
theme = 'default',
39+
viewport = {height: 200, width: 200},
3940
}) => {
4041

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

5152
await Promise.all(nodes.map(async node => {
5253
node.type = 'html';
53-
node.value = await render(browser, node.value, theme);
54+
node.value = await render(browser, node.value, theme, viewport);
5455
}));
5556
browser.close();
5657
};

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gatsby-remark-mermaid",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Add pretty graphs using mermaid and server-side rendering.",
55
"main": "index.js",
66
"repository": {

0 commit comments

Comments
 (0)