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
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,43 @@ diagram:
---
```

#### Mermaid

The Mermaid engine accepts various options corresponding to
a subset of the options that the `mmdc` command can take:

- `theme`: passes its value to `--theme`
- `background-color`: passes its value to `--backgroundColor`
- `config-file`: passes its value to `--configFile`
- `css-file`: passes its value to `--cssFile`
- `scale`: passes its value to `--scale`
- `puppeteer-config-file`: passes its value to `--puppeteerConfigFile`
- `icon-packs`: passes its value to `--iconPacks`

For more in-depth information on the meaning and format of every
option, use `mmdc --help`.

*Note* that for options that need to receive a file (e.g. `config-file`), relative paths can be used.
However they will be *relative to the working directory used when calling the `pandoc`
executable*, not to the directory of the file that contains the metadata block.

Example:

``` yaml
---
diagram:
engine:
mermaid:
theme: forest
background-color: white
config-file: mermaidConfig.json
css-file: cssFile.css
scale: 1
puppeteer-config-file: puppeteerConfig.json
icon-packs: "@iconify-json/logos"
---
```

Security
--------

Expand Down
35 changes: 24 additions & 11 deletions _extensions/diagram/diagram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,30 @@ local mermaid = {
local mime_type = self.mime_type or 'image/svg+xml'
local file_extension = extension_for_mimetype[mime_type]
return with_temporary_directory("diagram", function (tmpdir)
return with_working_directory(tmpdir, function ()
local infile = 'diagram.mmd'
local outfile = 'diagram.' .. file_extension
write_file(infile, code)
pipe(
self.execpath or 'mmdc',
{"--pdfFit", "--input", infile, "--output", outfile},
''
)
return read_file(outfile), mime_type
end)
local infile = pandoc.path.join({tmpdir, 'diagram.mmd'})
local outfile = pandoc.path.join({tmpdir, 'diagram.' .. file_extension})
--- Configure options for mmdc based on engine options
local args = List{'--pdfFit', '--input', infile, '--output', outfile}
if self.opt then
local options = {
['theme'] = '--theme',
['background-color'] = '--backgroundColor',
['config-file'] = '--configFile',
['css-file'] = '--cssFile',
['scale'] = '--scale',
['puppeteer-config-file'] = '--puppeteerConfigFile',
['icon-packs'] = '--iconPacks',
}
for opt, cliopt in pairs(options) do
if self.opt[opt] then
args:insert(cliopt)
args:insert(stringify(self.opt[opt]))
end
end
end
write_file(infile, code)
pipe(self.execpath or 'mmdc', args, '')
return read_file(outfile), mime_type
end)
end,
}
Expand Down
Empty file added test/cssFile.css
Empty file.
1 change: 1 addition & 0 deletions test/mermaidConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions test/puppeteerConfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
9 changes: 9 additions & 0 deletions test/test-mermaid.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,14 @@ metadata:
pagetitle: Mermaid diagram
diagram:
cache: false
engine:
mermaid:
theme: forest
background-color: white
config-file: test/mermaidConfig.json
css-file: test/cssFile.css
scale: 1
puppeteer-config-file: test/puppeteerConfig.json
icon-packs: "@iconify-json/logos"
variables:
document-css: false
Loading