diff --git a/README.md b/README.md index 3b18348..2453393 100644 --- a/README.md +++ b/README.md @@ -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 -------- diff --git a/_extensions/diagram/diagram.lua b/_extensions/diagram/diagram.lua index 37f4a62..01771ba 100644 --- a/_extensions/diagram/diagram.lua +++ b/_extensions/diagram/diagram.lua @@ -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, } diff --git a/test/cssFile.css b/test/cssFile.css new file mode 100644 index 0000000..e69de29 diff --git a/test/mermaidConfig.json b/test/mermaidConfig.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/test/mermaidConfig.json @@ -0,0 +1 @@ +{} diff --git a/test/puppeteerConfig.json b/test/puppeteerConfig.json new file mode 100644 index 0000000..0967ef4 --- /dev/null +++ b/test/puppeteerConfig.json @@ -0,0 +1 @@ +{} diff --git a/test/test-mermaid.yaml b/test/test-mermaid.yaml index bc5d98f..b4df10b 100644 --- a/test/test-mermaid.yaml +++ b/test/test-mermaid.yaml @@ -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