Pandoc Mermaid filter
Asked Answered
P

2

6

I am trying to use this pandoc filter to convert markdown to HTML. This is the example file:

gantt
        dateFormat  YYYY-MM-DD
        title Adding GANTT diagram functionality to mermaid
        section A section
        Completed task            :done,    des1, 2014-01-06,2014-01-08
        Active task               :active,  des2, 2014-01-09, 3d
        Future task               :         des3, after des2, 5d
        Future task2               :         des4, after des3, 5d
        section Critical tasks
        Completed task in the critical line :crit, done, 2014-01-06,24h
        Implement parser and jison          :crit, done, after des1, 2d
        Create tests for parser             :crit, active, 3d
        Future task in critical line        :crit, 5d
        Create tests for renderer           :2d
        Add to mermaid                      :1d

This is the command that I am running:

pandoc file.md -f markdown -o out.html --filter=pandoc-mermaid

This is the error message:

File "D:\Anaconda3\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "D:\Anaconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Anaconda3\Scripts\pandoc-mermaid.exe\__main__.py", line 7, in <module>
  File "D:\Anaconda3\lib\site-packages\pandoc_mermaid_filter.py", line 38, in main
    toJSONFilter(mermaid)
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 130, in toJSONFilter
    toJSONFilters([action])
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 164, in toJSONFilters
    sys.stdout.write(applyJSONFilters(actions, source, format))
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 195, in applyJSONFilters
    altered = walk(altered, action, format, meta)
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 123, in walk
    return {k: walk(v, action, format, meta) for k, v in x.items()}
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 123, in <dictcomp>
    return {k: walk(v, action, format, meta) for k, v in x.items()}
  File "D:\Anaconda3\lib\site-packages\pandocfilters.py", line 110, in walk
    res = action(item['t'],
  File "D:\Anaconda3\lib\site-packages\pandoc_mermaid_filter.py", line 31, in mermaid
    subprocess.check_call([MERMAID_BIN, "-i", src, "-o", dest])
  File "D:\Anaconda3\lib\subprocess.py", line 359, in check_call
    retcode = call(*popenargs, **kwargs)
  File "D:\Anaconda3\lib\subprocess.py", line 340, in call
    with Popen(*popenargs, **kwargs) as p:
  File "D:\Anaconda3\lib\subprocess.py", line 858, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "D:\Anaconda3\lib\subprocess.py", line 1311, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] El sistema no puede encontrar el archivo especificado
Error running filter pandoc-mermaid:
Filter returned error status 1

The folder where the executable is located is apparently added to path. Any ideas on how I could fix it?

Specifications: Windows 10 Home pandoc 2.14.0.1

Thanks

Polka answered 11/9, 2022 at 19:58 Comment(2)
Not sure what's happening there, but you could try Quarto. It's based on pandoc and ships with built-in support for mermaid. Try with quarto render file.md --to=htmlSirajuddaula
I'll sure do. Thanks!!Polka
Y
10

Not solving the problem but providing a different way to achieve the same and in case it's useful to others who arrive here:

Mermaid-cli has the feature to act as a preprocessor for Markdown.

As such, you can do the following:

mkdir build
npx -p @mermaid-js/mermaid-cli mmdc -i file.md -o build/output-svg.md
# Generates lots of output-svg-1.svg files linked from the doc
cd build
pandoc output-svg.md -o output.html

It defaults to SVG images (which generally works fine for HTML but fails when targeting PDF). It has a less well documented feature to force PNG generation.

npx -p @mermaid-js/mermaid-cli mmdc -i file.md --outputFormat=png \
    -o build/output-png.md
# Generates lots of output-png-1.png files linked from the doc
cd build
pandoc output-png.md -o output.pdf
Yhvh answered 6/11, 2022 at 16:7 Comment(1)
Thanks. This is a better solution for me. As with the mermaid-cli, I can now use the latest mermaid feature, while this is not possible with the mermaid-filter.Grose
I
8

I found success with the NPM library which adds a similar Mermaid filter for Pandoc: raghur/mermaid-filter.

You should be able to do:

pandoc file.md -f markdown -o out.html --filter=mermaid-filter

IMPORTANT: On Windows, you need to specify the filter as --filter mermaid-filter.cmd instead of --filter mermaid-filter (I missed this at first and was very confused)

Intercut answered 4/2, 2023 at 19:34 Comment(1)
For some reason, I was getting Chromium related errors. This post has resolved those issues for me: sachachua.com/blog/2023/10/…Evvie

© 2022 - 2024 — McMap. All rights reserved.