iamcco / markdown-preview.nvim

markdown preview plugin for (neo)vim
MIT License
6.67k stars 277 forks source link

Rendering mermaid C4 diagrams - parse error #519

Open sliptonic opened 1 year ago

sliptonic commented 1 year ago

Describe the bug C4 Diagram fails to render. Shows parse error

To Reproduce Steps to reproduce the behavior:

  1. Go to https://mermaid-js.github.io/mermaid/#/c4c
  2. Grab sample syntax for C4 context diagram
  3. Paste into a vimwiki file (surrounded by appropriate mermaid .... )
  4. See error. Parse error on line 1: C4Context ti ^ Expecting 'open_directive', 'NEWLINE', 'SPACE', 'GRAPH', got 'ALPHA'

Expected behavior Other diagram types render correctly. Same syntax renders correctly with mermaid-cli

Desktop (please complete the following information):

AphonicChaos commented 1 year ago

Same error for the (experimental) mind map example, which is to say that I don't think is specific to C4 diagrams.

rwyde commented 1 year ago

Figured it out. This plugin is bundling mermaid in the app/_static/ folder and I think its using an older version that doesn't support C4. They need to update that dependency. I found a workaround though that involves manually downloading and replacing it with the newer mermaid. You need to download mermaid.min.js from the cdn and then replace it in the installed location of markdown-preview. (Note that location may be different if you aren't using packer and that this process would need to be redone every time they push a new version of markdown-preview with the old dependency and you pull and install it I think) wget 'https://cdn.jsdelivr.net/npm/mermaid@9/dist/mermaid.min.js' mv mermaid.min.js ~/.local/share/nvim/site/pack/packer/opt/markdown-preview.nvim/app/_static/mermaid.min.js

sh-cau commented 1 year ago

The same error is thrown for timeline diagrams, @rwyde's fix results in the error changing to "undefined". The error is fixed using wget 'https://cdn.jsdelivr.net/npm/mermaid@10.2.0-rc.2/dist/mermaid.min.js'.

christoph-blessing commented 1 year ago

I got the same error when trying to create a namespace in a class diagram. Using mermaid@10.2.2 fixed it.