Skip to content
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

Updated: Support multi-word mermaid commands #138

Merged
merged 5 commits into from
Jun 3, 2024
Merged
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
11 changes: 9 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,22 @@ Config values

``mermaid_init_js``

Mermaid initilizaction code. Default to ``"mermaid.initialize({startOnLoad:true});"``.
Mermaid initialization code. Default to ``"mermaid.initialize({startOnLoad:true});"``.

.. versionchanged:: 0.7
The init code doesn't include the `<script>` tag anymore. It's automatically added at build time.


``mermaid_cmd``

The command name with which to invoke ``mermaid-cli`` program. The default is ``'mmdc'``; you may need to set this to a full path if it's not in the executable search path.
The command name with which to invoke ``mermaid-cli`` program.
The default is ``'mmdc'``; you may need to set this to a full path if it's not in the executable search path.
If a string is specified, it is split using `shlex.split` to support multi-word commands.
To avoid splitting, a list of strings can be specified.
Examples::

mermaid_cmd = 'npx mmdc'
mermeid_cmd = ['npx', '--no-install', 'mmdc']

``mermaid_cmd_shell``

Expand Down
8 changes: 7 additions & 1 deletion sphinxcontrib/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import codecs
import errno
import os
import shlex
import posixpath
import re
from hashlib import sha1
Expand Down Expand Up @@ -197,8 +198,13 @@ def render_mm(self, code, options, _fmt, prefix="mermaid"):
with open(tmpfn, "w") as t:
t.write(code)

mm_args = [mermaid_cmd, "-i", tmpfn, "-o", outfn]
if isinstance(mermaid_cmd, str):
mm_args = shlex.split(mermaid_cmd)
else:
mm_args = list(mermaid_cmd)

mm_args.extend(self.builder.config.mermaid_params)
mm_args += ['-i', tmpfn, '-o', outfn]
if self.builder.config.mermaid_sequence_config:
mm_args.extend("--configFile", self.builder.config.mermaid_sequence_config)

Expand Down
Loading