Skip to content

Commit

Permalink
Merge pull request #138 from tuncbkose/multi-word-commands
Browse files Browse the repository at this point in the history
Updated: Support multi-word mermaid commands
  • Loading branch information
mgaitan authored Jun 3, 2024
2 parents f1e03c7 + b8ddecb commit 7922ed7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
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

0 comments on commit 7922ed7

Please sign in to comment.