Looking for an enhancement. Is there any plan to support the diagrams usage in material?
What are mermaid diagrams?
This question was brought up in pymdown-extensions: https://github.com/facelessuser/pymdown-extensions/issues/60. SuperFences is used to create the UML diagrams currently accessible, but you can configure SuperFences to generate such blocks differently, then include necessary JavaScript and CSS to render them in the browser.
I don't provide multiple different examples of every UML library out there, and I leave it up to users to do the work for their favorite library. You are free to create a wiki page over at pymdown-extensions to detail how you got it working so that others can get going with mermaid (I think I allow the public to edit/create pages).
Anyways, check out the linked issue for more info.
Since the mermaid support need to be added as part of the extension, it can be closed.
It doesn't need to be added as part of the extension, you just need to utilize the extension options to add support in your documents yourself.
Anyone been able to do it?
This discussion mentions "you should be able to do it" but no pointers where to look.
https://www.mkdocs.org/user-guide/configuration/ references nonexistent site: https://pythonhosted.org/Markdown/extensions/index.html
I googled the "python markdown", found https://python-markdown.github.io/extensions/
But there's no mention of mermaid even in "3rd party extensions"
On mermaid website https://github.com/knsv/mermaid there's no mention how to integrate it either.
@romanr
The trick is:
This is the relevant section in the doc: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/#custom-fences
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_div_format
extra_css:
- https://unpkg.com/[email protected]/dist/mermaid.css
extra_javascript:
- https://unpkg.com/[email protected]/dist/mermaid.min.js
And then write your mermaid code as follow:
````markdown
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
````
Not working anymore ?
@dobl1, you would need to be very specific in what you are doing that isn't working. Also Material doesn't support Mermaid out of the box. This requires users to setup their own custom fences via pymdownx-superfences. In addition, if Mermaid changes how they do things, then you may need to provide your own custom formatter.
Regardless, I'm not sure this is a Material question. Maybe hop on over to pymdown-extensions and provide actual details that can be used to help guide you to a solution?
for me, links don't work anylonger,
maybe because of the new security implementation with mermaid-version 8.2: https://mermaid-js.github.io/mermaid/#/?id=special-note-regarding-version-82 ?
If yes, my question would be where to set securityLevel: 'loose' or =false.
I'm using pymdown-extensions version 5.0
my mkdocs.yml (currently):
extra_javascript:
- https://unpkg.com/[email protected]/dist/mermaid.min.js
markdown_extensions:
- pymdownx.superfences:
custom_fences:
- name: mermaid
class: mermaid
format: !!python/name:pymdownx.superfences.fence_div_format
my mermaid-code example:
A --- B
click B "https://www.google.com"
I'm assuming you'd include it in your own JavaScript file which you would also need to include.
I was able to get this working. Updating the ticket with the latest mermaidjs version number:
```markdown_extensions:
extra_css:
````
```mermaid
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
````
https://unpkg.com/[email protected]/dist/mermaid.css is not found
Got this error message
Cannot find "/dist/mermaid.css" in [email protected]
Is this normal?
Yes because Mermaid no longer provides CSS assets. They have an internal system that you configure through options to use different themes (or you can turn off themes and provide your own
CSS as pymdown-extensions does in it's documentation: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/#custom-fences.
This is more a Mermaid question though.
Thank you @facelessuser !
Just in case, there is now a mermaid plugin (which I'm maintaining) called mkdocs-mermaid2 which is compatible with superfences:
Why can't we just use custom fences, which is natively supported by SuperFences? What does the plugin do "more"?
For complete beginners who don't know anything about the beauty of SuperFences, this plugin would be a solution out of the box.
For advanced users who really want to tweak the diagrams, the plugin provides documented use cases and allows good flexibility, typically if you want to use the mkdocs.yaml file to pass arguments to the javascript initialize() function. It also documents how to declare your own callback javascript function.
For Superfences users who are in the goldilocks zone, I wouldn't suggest a change (if it ain't broke, don't fix it 馃檪). The plugin's doc shows how to make it work with SuperFences, so IMHO it should be a complement, not an alternative.
Thanks for the explanation! I still have the reference documentation for using Mermaid diagrams with Material for MkDocs on my list and will think about what to recommend. Personally, I have had a great experience with SuperFences, but I'll try your plugin and see whether it provides a significant improvement of the user experience.
I have no comments on whether the plugin is good or not, only that I know @fralau was working on it. I'd be interested to hear if people find it helps. I know it still relies on SuperFences. But I haven't bothered to look into anything else. I think once I got Mermaid up and running (and recently styled) the way I wanted, I had no need to revisit.
If I get some time, maybe I'll try it out. If it smooths over some pain points, I wouldn't mind referencing it from SuperFences documentation when I talk about Mermaid. I'd love to offload Mermaid questions 馃檭 .
I joke, but I only get Mermaid questions on rare occasions. But even still, I'd much rather focus on answering questions more pertinent to the extensions themselves opposed to custom use cases 馃檪.
I am a complete beginner and could not set config params using custom fences, even after carefully stepping through the Advanced Mermaid Notes and trying both snippets as well as extra_javascript imports.
However setting the config in the plugin worked nicely, eg
plugins:
- search
- mermaid2:
arguments:
sequence:
mirrorActors: false
I since discovered that config can also be applied via Directives, which works with the custom fences (without the plugin)
'''mermaid
sequenceDiagram
%%{init:{'sequence':{'mirrorActors': false}}}%%
participant John
participant Alice
Alice->>John: Hello John, how are you?
John-->>Alice: Great!
'''
@s1monj that is useful feedback that seems to confirm how things are evolving. No plugins for Mermaid are needed, if the user is in the "Goldilocks zone" , i.e. :
mkdocs.yaml, markdown extensions and extra javascript)When diagrams get more complicated (initiazation sequences, callbacks, etc.), then things get different. At some point, the requirements will exceed the personal ressources (Competence/Time/Interest) one is willing to invest.
Indeed, mermaid Directives are a great innovation to solve "one-off" needs (i.e. there are a couple of mermaid diagrams in the project and one needs to define how _that specific_ diagram should behave).
The mermaid2 plugin is more aimed at those who require a _framework_ to work with Mermaid diagrams. That could be:
Note that the Directives and the mermaid2 plugin should be able to work together, to a large degree.
Most helpful comment
@romanr
The trick is:
This is the relevant section in the doc: https://facelessuser.github.io/pymdown-extensions/extensions/superfences/#custom-fences
And then write your mermaid code as follow:
````markdown
````