timofurrer / pandoc-mermaid-filter

Pandoc filter for mermaid code blocks
MIT License
78 stars 22 forks source link

`mmdc` not recognized as executable on windows #19

Open mivanit opened 2 years ago

mivanit commented 2 years ago

I've explicitly set MERMAID_BIN = 'path/to/mermaid-cli/node_modules/.bin/mmdc/ in the python code and tested that mmdc works when run from the shell. When trying to run the filter, I get

Traceback (most recent call last):
  File "f:\Gdrive\notes\tools\pandoc\filters\mermaid.py", line 57, in <module>
    main()
  File "f:\Gdrive\notes\tools\pandoc\filters\mermaid.py", line 53, in main
    toJSONFilter(mermaid)
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 148, in toJSONFilter
    toJSONFilters([action])
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 182, in toJSONFilters
    sys.stdout.write(applyJSONFilters(actions, source, format))
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 213, in applyJSONFilters
    altered = walk(altered, action, format, meta)
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 141, in walk
    return {k: walk(v, action, format, meta) for k, v in x.items()}
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 141, in <dictcomp>
    return {k: walk(v, action, format, meta) for k, v in x.items()}
  File "C:\Python\Python3_10\lib\site-packages\pandocfilters.py", line 128, in walk
    res = action(item['t'],
  File "f:\path\to\pandoc-mermaid-filter.py", line 46, in mermaid
    subprocess.check_call(cmd)
  File "C:\Python\Python3_10\lib\subprocess.py", line 364, in check_call
    retcode = call(*popenargs, **kwargs)
  File "C:\Python\Python3_10\lib\subprocess.py", line 345, in call
    with Popen(*popenargs, **kwargs) as p:
  File "C:\Python\Python3_10\lib\subprocess.py", line 966, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Python\Python3_10\lib\subprocess.py", line 1435, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
OSError: [WinError 193] %1 is not a valid Win32 application

setting shell=True for subprocess.check_call fixes the issue, but this is probably not the most elegant solution. I'm not familiar with node.js so I'm not sure what exactly the problem might be.