asciidoctor / asciidoctor-diagram

:left_right_arrow: Asciidoctor diagram extension, with support for AsciiToSVG, BlockDiag (BlockDiag, SeqDiag, ActDiag, NwDiag), Ditaa, Erd, GraphViz, Mermaid, Msc, PlantUML, Shaape, SvgBob, Syntrax, UMLet, Vega, Vega-Lite and WaveDrom.
http://asciidoctor.org
MIT License
442 stars 107 forks source link

Mermaid support: mmdc failed #275

Closed jnnkB closed 4 years ago

jnnkB commented 4 years ago

I tried to use the mermaid support but if run asciidoctor i get

asciidoctor: ERROR: test.adoc: line 6: Failed to generate image: mmdc failed: 
Please specify input file: -i <input>

A minimal file which shows the same error is:

:mermaid: ./node_modules/.bin/mmdc
:phantomjs_19: ./node_modules/.bin/phantomjs

[mermaid]
----
classDiagram      
      class Animal {
          +int age
    }

----

Thanks!

pepijnve commented 4 years ago

I've tried to reproduce this locally, seems to work correctly for me. I tested with asciidoctor 2.0.10, asciidoctor-diagram 2.0.1 and mmdc 0.5.1 on macOS.

jnnkB commented 4 years ago

I've made a demo zip: Archive.zip

Here is the output form the command line:


$ bundle exec asciidoctor test.adoc -r asciidoctor-diagram
asciidoctor: ERROR: test.adoc: line 6: Failed to generate image: Could not find the 'phantomjs' executable in PATH; add it to the PATH or specify its location using the 'phantomjs_2' document attribute
pepijnve commented 4 years ago

Seeing that phantom error reminded me there are two sets of attributes that the mermaid extension supports: mermaid + phantomjs_2 or mmdc. The former is for old version of mermaid's CLI, the latter is for the current CLI.

Could you try replacing the attributes in your test document with:

:mmdc: ./node_modules/.bin/mmdc
jnnkB commented 4 years ago

I then get the following error:

asciidoctor: ERROR: test.adoc: line 4: Failed to generate image: Could not find the 'mermaid' executable in PATH; add it to the PATH or specify its location using the 'mermaid' document attribute

test.adoc:

:mmdc: ./node_modules/.bin/mmdc

[mermaid]
----
classDiagram      
      class Animal {
          +int age
    }

----
pepijnve commented 4 years ago

Which version of asciidoctor and asciidoctor-diagram are you using?

jnnkB commented 4 years ago
$ bundle install
Using asciidoctor 2.0.10
Using asciidoctor-diagram 2.0.1
Using bundler 2.1.4
Bundle complete! 2 Gemfile dependencies, 3 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
$ bundle exec asciidoctor test.adoc -r asciidoctor-diagram
asciidoctor: ERROR: test.adoc: line 6: Failed to generate image: Could not find the 'mermaid' executable in PATH; add it to the PATH or specify its location using the 'mermaid' document attribute
pepijnve commented 4 years ago

@jnnkB On which operation system (and version) is that? Just trying to get as good a reproduction setup as possible.

jnnkB commented 4 years ago

macOS 10.15.3

pepijnve commented 4 years ago

@jnnkB I've tried to reproduce this on essentially the same setup, but no luck. I've added some debug logging to the command lookup code in fd152ec8a1e5e8b35f8465c0c86306805bb67089. You can enable the debug output by running asciidoctor with the --verbose option.

jnnkB commented 4 years ago

Ok so I changed the Gemfile to

# frozen_string_literal: true

source "https://rubygems.org"

gem 'asciidoctor'
gem 'asciidoctor-diagram', git: 'https://github.com/asciidoctor/asciidoctor-diagram.git', ref: 'fd152ec8a1e5e8b35f8465c0c86306805bb67089'

Then I installed the dependencys

$ npm install @mermaid-js/mermaid-cli phantomjs
<NPM OUTPUT>
$ bundle install
<BUNDLE OUTPUT>

Now I ran asciidoctor:

$ bundle exec asciidoctor test.adoc --doctype=book -r asciidoctor-diagram --verbose
asciidoctor: DEBUG: Finding 'mmdc' in attributes
asciidoctor: DEBUG: Finding 'mmdc' in environment
asciidoctor: DEBUG: Finding 'mermaid' in attributes
asciidoctor: DEBUG: Found value './node_modules/.bin/mmdc' in attribute 'mermaid'
asciidoctor: DEBUG: Expanded './node_modules/.bin/mmdc' to '~/Archive/node_modules/.bin/mmdc'
asciidoctor: DEBUG: Is '~/Archive/node_modules/.bin/mmdc' executable? true
asciidoctor: DEBUG: Finding 'phantomjs' in attributes
asciidoctor: DEBUG: Finding 'phantomjs' in environment
asciidoctor: ERROR: test.adoc: line 6: Failed to generate image: Could not find the 'phantomjs' executable in PATH; add it to the PATH or specify its location using the 'phantomjs_2' document attribute

So I changed the test.adoc to:

:mermaid: ./node_modules/.bin/mmdc
:phantomjs_2: ./node_modules/.bin/phantomjs

[mermaid]
----
classDiagram      
      class Animal {
          +int age
    }

----

Now I got the following error:

$ bundle exec asciidoctor test.adoc --doctype=book -r asciidoctor-diagram --verbose
asciidoctor: DEBUG: Finding 'mmdc' in attributes
asciidoctor: DEBUG: Finding 'mmdc' in environment
asciidoctor: DEBUG: Finding 'mermaid' in attributes
asciidoctor: DEBUG: Found value './node_modules/.bin/mmdc' in attribute 'mermaid'
asciidoctor: DEBUG: Expanded './node_modules/.bin/mmdc' to '~/Archive/node_modules/.bin/mmdc'
asciidoctor: DEBUG: Is '~/Archive/node_modules/.bin/mmdc' executable? true
asciidoctor: DEBUG: Finding 'phantomjs' in attributes
asciidoctor: DEBUG: Found value './node_modules/.bin/phantomjs' in attribute 'phantomjs_2'
asciidoctor: DEBUG: Expanded './node_modules/.bin/phantomjs' to '~/Archive/node_modules/.bin/phantomjs'
asciidoctor: DEBUG: Is '~/Archive/node_modules/.bin/phantomjs' executable? true
asciidoctor: ERROR: test.adoc: line 6: Failed to generate image: mmdc failed:
Please specify input file: -i <input>

Now I remembered that I could try it with mmdc in test.adoc instead of mermaid and phatomjs. So I changed test.adoc to

:mmdc: ./node_modules/.bin/mmdc

[mermaid]
----
classDiagram      
      class Animal {
          +int age
    }

----

And it worked:

$ bundle exec asciidoctor test.adoc --doctype=book -r asciidoctor-diagram --verbose                                                 
asciidoctor: DEBUG: Finding 'mmdc' in attributes
asciidoctor: DEBUG: Found value './node_modules/.bin/mmdc' in attribute 'mmdc'
asciidoctor: DEBUG: Expanded './node_modules/.bin/mmdc' to '~/Archive/node_modules/.bin/mmdc'
asciidoctor: DEBUG: Is '~/Archive/node_modules/.bin/mmdc' executable? true

I tried to uninstall phantomjs:

$ npm uninstall phantomjs

And that worked too.

So this is what I finally ended up with: Archive.zip

Thanks a lot for your help. Should I close the issue now?

I think maybe the documentation should mention :mmdc: So one could change

Diagram Type Tool Attribute
mermaid Mermaid.cli mermaid

to

Diagram Type Tool Attribute
mermaid Mermaid.cli mermaid / mmdc
pepijnve commented 4 years ago

The mmdc attribute is the one to use indeed. mermaid/phantomjs are there to support very old version of Mermaid. I'll update the README indeed. Forgot about that.

pepijnve commented 4 years ago

I ended up removing the mermaid attribute. That's only still there in the code for backwards compatibility; new users shouldn't be using this.

pepijnve commented 4 years ago

Thanks for testing @jnnkB. AFAICT this should already work with 2.0.2 as well. Not sure why it wasn't working before. I did make one extra mermaid related change that solves #257. I'll make a new patch release for that one later this week.

jnnkB commented 4 years ago

I ended up removing the mermaid attribute. That's only still there in the code for backwards compatibility; new users shouldn't be using this.

Sounds good. Will https://asciidoctor.org/docs/asciidoctor-diagram/ update itself automatically.

OliverO2 commented 4 years ago

@pepijnve As the legacy mermaid attribute has been removed from the README, this code should probably change as well: https://github.com/asciidoctor/asciidoctor-diagram/blob/cd85628edce8db9aeed11b877fc0d8599c92fb65/lib/asciidoctor-diagram/mermaid/converter.rb#L80

Currently, mmdc is checked first, then mermaid – which is OK, but makes asciidoctor-diagram propose to set the obsolete mermaid document attribute, which is now misleading:

Failed to generate image: Could not find the 'mermaid' executable in PATH; add it to the PATH or specify its location using the 'mermaid' document attribute

Cf. https://github.com/asciidoctor/asciidoctor-intellij-plugin/issues/534#issuecomment-702839033

Extra note: It seems that asciidoctor-diagram successfully discovers mermaid in PATH, but not mmdc (when both mmdc and node were accessible via PATH). To make mmdc work, I always had so set the mmdc document attribute.

EDITS: