-
-
Notifications
You must be signed in to change notification settings - Fork 17
Mermaid options to configure mmdc #60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you! I didn't find the time yet to review this, but it's on my list! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thanks a lot!
I've added a few inline comments, but nothing major. Just let me know if you don't have time to fix it yourself, then I'll merge as-is and do the changes later.
_extensions/diagram/diagram.lua
Outdated
local outfile = tmpdir .. '/diagram.' .. file_extension | ||
--- Configure options for mmdc based on engine options | ||
local args = {'--pdfFit', '--input', infile, '--output', outfile} | ||
setmetatable(args, {__index = {insert = table.insert}}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using pandoc.List {...}
in the line above would make this line unnecessary.
_extensions/diagram/diagram.lua
Outdated
local args = {'--pdfFit', '--input', infile, '--output', outfile} | ||
setmetatable(args, {__index = {insert = table.insert}}) | ||
if self.opt then | ||
if self.opt['theme'] then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The repeated if
statements seems a bit clunky to me. How about defining a table that maps option keys to command line arguments, and then loop over that table in a for loop? Something along the lines of
local options = { theme = '--theme', ...}
for opt, cliopt in pairs(options) do
...
end
_extensions/diagram/diagram.lua
Outdated
) | ||
return read_file(outfile), mime_type | ||
end) | ||
local infile = tmpdir .. '/diagram.mmd' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use pandoc.path.join
here to ensure that we are using the correct directory separator. It probably won't matter, but it's good style.
I'll try to work on it this week |
Hello, sorry for the wait, I've applied the changed as requested. Now the only issue is the GitHub workflow failing. A possible solution would be to set the diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml
index ac493a7..f3f8eb5 100644
--- a/.github/workflows/ci.yaml
+++ b/.github/workflows/ci.yaml
@@ -81,7 +81,6 @@ jobs:
image: pandoc/core:${{ matrix.pandoc }}
env:
- MERMAID_BIN: /usr/local/bin/mmdc-test
PUPPETEER_EXECUTABLE_PATH: /usr/bin/chromium-browser
steps:
@@ -93,10 +92,6 @@ jobs:
run: |
apk update && apk add chromium chromium-chromedriver make npm
npm install -g @mermaid-js/mermaid-cli
- printf '{"args":["--no-sandbox","--disable-setuid-sandbox", "--disable-gpu"]}' > \
- /etc/puppeteer-conf.json
- printf '#!/bin/sh\nmmdc -p /etc/puppeteer-conf.json $@' > $MERMAID_BIN
- chmod +x $MERMAID_BIN
- name: Test
run: 'make test-mermaid'
diff --git a/test/puppeteerConfig.json b/test/puppeteerConfig.json
index 0967ef4..5d14311 100644
--- a/test/puppeteerConfig.json
+++ b/test/puppeteerConfig.json
@@ -1 +1 @@
-{}
+{"args":["--no-sandbox","--disable-setuid-sandbox", "--disable-gpu"]} This would also make some code unnecessary in the workflow file, that's why I've removed it in the code block above. The only problem with this is that this configuration, which disables the sandbox security feature of chrome, would also be applied to tests executed in developers' computers, but I don't think this is a problem considering we control the code that the browser executes. Let me know if you want me to commit this. |
Thank you! I think my preferred method would be to remove |
Changes
Fixes and enhances #44:
Clarifications regarding #31
This may close #31, but given what @reagle asked for, I think there needs to be some clarification.
First I'm not aware that Mermaid will read a
mermaid-config.json
automatically, so to change Mermaid's configuration for the entiretypandoc
execution, you should create a mermaid configuration file and add it to the options of this filter.For example, if we name the file
mermaid.json
and executepandoc
in the same directory where this file resides, this would be the metadata block needed:If you need to change Mermaid's configuration for a single diagram, then you will need to use Mermaid's frontmatter configuration, which is independent from this filter and built into Mermaid.
Note that the first configuration has to be written in json, whilst the second one is yaml.