GithubHelp home page GithubHelp logo

fralau / mkdocs-mermaid2-plugin Goto Github PK

View Code? Open in Web Editor NEW
204.0 1.0 25.0 1.02 MB

A Mermaid graphs plugin for mkdocs

Home Page: https://mkdocs-mermaid2.readthedocs.io

License: MIT License

Python 58.51% Shell 3.15% JavaScript 38.34%
mkdocs-plugin mkdocs mermaid mermaid-diagrams

mkdocs-mermaid2-plugin's Introduction

Mkdocs-Mermaid2

License: MIT PyPI Github Downloads(PyPI)

An MkDocs plugin that renders Mermaid text descriptions into diagrams (flow charts, sequence diagrams, pie charts, etc.).


As of version 1.0.0, this plugin works with versions of the Mermaid library > 10, and with lower versions.

Introduction

Mermaid2 allows you to insert mermaid markup in the markdown of your mkdocs pages.

For example, a markdown page containing the following diagram:

```mermaid
graph LR
    hello --> world
    world --> again
    again --> hello
```

will then be displayed in the final HTML page as:

graph LR
    hello --> world
    world --> again
    again --> hello
Loading

The diagram will be rendered on the fly by the web browser, with the use of the mermaid javascript library. mkdocs-mermaid2 takes care of inserting the javascript library into the html page.

You can use all the diagrams types supported by the version of the Mermaid javascript library that you are using (flowchart, class, state, timeline, etc.).

Installation

Automatic

pip install mkdocs-mermaid2-plugin

Manual

Clone this repository in a local directory and install the package:

python setup.py install

Test

For running the examples the test directory, you will also need the mkdocs-material theme. You may install it directly, or use the following command to install the whole package:

pip install mkdocs-mermaid2-plugin[test]

Configuration

Basic configuration

To enable this plugin, you need to declare it in your mkdocs config file (mkdocs.yml).

In order to work, the plugin also requires the mermaid javascript library (in the example below, it fetched from the last version from the unpkg repository; change the version no as needed).

plugins:
    - search
    - mermaid2

Note: If you declare plugins, you need to declare all of them, including search (which would otherwise have been installed by default.)

Specifying the version of the Mermaid library

By default, the plugin selects a version of the Mermaid javascript library that is known to work (some versions work better than others).

You may specify a different version of the Mermaid library, like so:

plugins:
  - search
  - mermaid2:
      version: 10.0.2

The plugin will insert the correct call to the javascript library inside the final HTML page.

Additional settings for the Material theme

The Material theme, developed by squidfunk is not mandatory, but recommended.

Mermaid diagrams will automatically adapt their colors to the theme and palette.

Here are the additional recommended settings in the configuration file:

markdown_extensions:
  - pymdownx.superfences:
        # make exceptions to highlighting of code:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid_custom

Do not use these additional settings for other themes, as diagrams will probably not be displayed correctly.

For more information

See the documentation on ReadTheDocs.

mkdocs-mermaid2-plugin's People

Contributors

cmungall avatar d4nyl0 avatar fralau avatar jannschu avatar julienlavergne avatar kratsg avatar lofidevops avatar patrislav1 avatar peterjclaw avatar pugong avatar ribetm avatar sblaisot avatar thatgaypigeon avatar ultrabug avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

mkdocs-mermaid2-plugin's Issues

Syntax Error Due to Incorrect Generated HTML File

Not sure if this issue is being faced by me or others as well. Mermaid diagrams won't render for me no matter what - I checked my formatting, syntax, etc, but kept getting the Syntax Error image.

image

After checking the generated HTML files, I saw the HTML code was generated as follows.

<pre><code class="mermaid">graph TD
  A[Client] --&gt; B[Load Balancer]
  B --&gt; C[Server01]
  B --&gt; D[Server02]
</code></pre>

As you can see, it shows up as <code> ... </code>. I manually changed it to <div>...</div> and the diagrams generated just fine.

<pre><div class="mermaid">graph TD
  A[Client] --&gt; B[Load Balancer]
  B --&gt; C[Server01]
  B --&gt; D[Server02]
</div></pre>

image

Running mkdocs build reverts it back to code and so syntax errors start occurring again.

Attaching my yml file for reference:

site_name: My Documentation
nav:
  - Home: index.md
  - Modules: modules.md
theme: readthedocs
plugins:
  - search
  - mermaid2
extra_javascript:
  - https://unpkg.com/mermaid/dist/mermaid.min.js
markdown_extensions:
  - admonition

Doesn't work with Material for MkDocs theme and SuperFences extension

More of an informational issue.

When combined with Material for MkDocs theme and SuperFences extension, the mermaid plugin stops working.

MkDocs Version

$ mkdocs --version
mkdocs, version 1.1.2 (Python 3.7)

MkDocs Configuration (mkdocs.yml)

site_name: My Docs
theme: material
markdown_extensions:
  - pymdownx.superfences
plugins:
    - mermaid2
extra_javascript:
    - https://unpkg.com/mermaid/dist/mermaid.min.js

Unfortunately I haven't been able to resolve this issue.

Prettified tag does not seem to work with arguments provided in mkdocs.yml

EDIT: updated the title, check the second comment.

Just upgraded to 0.4.2 and it seems arguments passed to mermaid2 are not used anymore.

plugins:
  - search
  - mermaid2:
      arguments:
        theme: forest
        flowchart:
          curve: basis

With 0.4.1 the graph are correctly themed with forest and edges are rounded.
With 0.4.2 the default theme is used and edges are "hard" (linear).

To reproduce:

git clone https://github.com/pawamoy/copier
cd copier
git checkout docs-graph
poetry install
poetry run mkdocs serve
# go to localhost:8000/updating/#how-the-update-works

# now install 0.4.1 and check again
poetry run pip install mkdocs-mermaid2-plugin==0.4.1
poetry run mkdocs serve
# go to localhost:8000/updating/#how-the-update-works

With both 0.4.1 and 0.4.2, the version 8.6.4 of mermaid-js is used.

By the way in both 0.4.1 and 0.4.2 I need to specify the custom fence for it to work.

By default, take the latest version of mermaid library?

Currently, mkdocs-mermaid2 seems to take by default the MERMAID_LIB_VERSION.

We could also use an approach where it takes the latest version of the mermaid library by default.

It happened once in the past, that the latest version was problematic, and it broke the build. Which is why we wanted to keep control on the 'recommended' (stable) version

We could have a compromise solution?

imcompatibility with minify plugin

Dear @fralau,

I detected an incompatibility between mkdocs-mermaid2-plugin and minify

This does not work:

site_name: Ma doc

theme:
  name: material
  font: false
  language: 'fr'
  feature:
    tabs: true
  palette:
    scheme: default
    primary: 'blue grey'
    accent: 'orange'

plugins:
  - search
  - mermaid2:
      arguments:
        theme: 'dark'
  - minify:
      minify_html: true

markdown_extensions:
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid

extra_javascript:
  - https://unpkg.com/[email protected]/dist/mermaid.min.js

use_directory_urls: false
nav:
  - Accueil: index.md

but work without the lines

  - minify:
      minify_html: true

the diagram type |mindmap| seems to be broken

The mindmap diagram seems to be broken even when using the latest mermaid js library.

mindmap
  root((start))
    node 1
        node 2
    node 3
        node 4

Gives me this error:

image

The link to the mermaid live editor is here

This is the part of mkdocs that configures this plugin:

plugins:
  - mermaid2:
extra_javascript:
    - https://unpkg.com/mermaid/dist/mermaid.min.js
markdown_extensions:
  - pymdownx.highlight
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:pymdownx.superfences.fence_code_format

Annotations in class diagram not working with SuperFences

Source:

classDiagram
  class Foo
  <<abstract>> Foo

Expected:

classDiagram
  class Foo
  <<abstract>> Foo
Loading

Actual:

image

Here's the mkdocs.yml, if I disable SuperFences it works as expected.

site_name: Test

docs_dir: docs

plugins:
  - mermaid2

markdown_extensions:
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid

mkdocs==1.3.1
mkdocs-mermaid2-plugin==0.6.0
pymdown-extensions==9.5

Overflowing graph + wrapped node text

I was trying to generate these mermaid flowcharts when I found that the nodes don't get resized properly in order to show all of the text - badly cropped text follows:

mermaid
graph TD;
coords("(2N,M) particle coordinates")-->dist_mat(Distance matrix D);
coords -- PCA --> one_d("(2N, 1) One Dimensional Projection")
one_d -- sort --> approx_soln(Approximate Pairing)
dist_mat --> obj(Approximate target value)
approx_soln --> obj

Screenshot 2022-03-07 at 11 14 30

When trying to fix this, I also found that making the graph go from left to right causes it to overflow:

mermaid
graph LR;
coords("(2N,M) particle coordinates")-->dist_mat(Distance matrix D);
coords -- PCA --> one_d("(2N, 1) One Dimensional Projection")
one_d -- sort --> approx_soln(Approximate Pairing)
dist_mat --> obj(Approximate target value)
approx_soln --> obj

Screenshot 2022-03-07 at 11 13 56

These issues don't occur when rendering the mermaid graphs elsewhere (eg VSCode, on Gitlab) so it shouldn't be an issue with native mermaid.

Interested in code QA ?

Hi, thanks for your time on this plugin.

Just wanted to know if you'd be interested in adding code QA to this repo ? something like black + isort + flake8 would be good for the code base maybe.

Cheers

Unneccesary inclusion of mkdocs-material

setup.py includes the mkdocs-material theme as a requirement. This means that I have to install the theme (and its dependencies) even if I don't use it. Could this be made an optional dependency? If so I'm happy to work on making the change.

setup.py

    install_requires=[
        'setuptools>=18.5',
        'beautifulsoup4>=4.6.3',
        'mkdocs>=1.0.4',
        'jsbeautifier',
        'pyyaml', # for testing
        'mkdocs-material', # for testing
        'requests',
        'pymdown-extensions >= 8.0'
    ],

Relevant documentation

cannot find 'fence_mermaid' in the module 'mermaid2'

Hello,
I encounter this following bug:

INFO    -  Building documentation...

MkDocs encountered as error parsing the configuration file: while constructing a Python object
cannot find 'fence_mermaid' in the module 'mermaid2'
  in "/home/unger/tmp/test/mkdocs-mermaid2/mkdocs-mermaid2-plugin/test/mkdocs.yml", line 24, column 19

Steps to reproduce the bug

  1. git clone https://github.com/fralau/mkdocs-mermaid2-plugin
cd mkdocs-mermaid2-plugin
sudo python setup.py install
cd test
python -m mkdocs serve

It seems that mkdocs cannot find fence_mermaid in mermaid2

          format: !!python/name:mermaid2.fence_mermaid

Thanks for your help

Release 0.4.3

Hello! Could you publish a new release for version 0.4.3 on PyPI?

Graph only visible on reload

Hi,

thank you for providing this plugin!
In my case the graph is placed in a tab (using superfences).
If I initially load the page and click on the tab it does not show the graph. It appears only when I reload the page.

I`m using version 0.6.0 of this library and the following plugins:

plugins:
  - search
  - mermaid2
  - print-site

New release

Would it be possible to publish a new release to pick up changes from this year? In particular, I'm looking to stop seeing "FOUND: 0" spam that was fixed in 2b476c1

Plugin Incompatible with readthedocs.org

The mkdocs-mermaid2-plugin seems to be incompatible with readthedocs.org. the build pipeline on readthedocs.org fails with the error shown below.

Python version: 3.7.9
Mkdocs version: 1.1.2
mkdocs-mermaid2-plugin version: 0.5.1

INFO    -  MERMAID2  - Initialization arguments: {}
INFO    -  MERMAID2  - Using javascript library (8.8.0):
   https://unpkg.com/[email protected]/dist/mermaid.min.js
INFO    -  Cleaning site directory
INFO    -  Building documentation to directory: /home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/checkouts/latest/_build/html
INFO    -  MERMAID2  - Found superfences config: {'custom_fences': [{'class': 'mermaid', 'format': None, 'name': 'mermaid'}]}
ERROR   -  Error building page 'index.md': 'NoneType' object has no attribute '__name__'
Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mermaid2/plugin.py", line 95, in activate_custom_loader
    return self._activate_custom_loader
AttributeError: 'MarkdownMermaidPlugin' object has no attribute '_activate_custom_loader'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/docs/.pyenv/versions/3.7.9/lib/python3.7/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/home/docs/.pyenv/versions/3.7.9/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mkdocs/__main__.py", line 192, in <module>
    cli()
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mkdocs/__main__.py", line 152, in build_command
    build.build(config.load_config(**kwargs), dirty=not clean)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mkdocs/commands/build.py", line 292, in build
    _build_page(file.page, config, files, nav, env, dirty)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mkdocs/commands/build.py", line 214, in _build_page
    'post_page', output, page=page, config=config
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mkdocs/plugins.py", line 94, in run_event
    result = method(item, **kwargs)
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mermaid2/plugin.py", line 159, in on_post_page
    if self.activate_custom_loader:
  File "/home/docs/checkouts/readthedocs.org/user_builds/onegini-onegini-public-docs-parent/envs/latest/lib/python3.7/site-packages/mermaid2/plugin.py", line 117, in activate_custom_loader
    if format_fn.__name__ == CUSTOM_FENCE_FN:
AttributeError: 'NoneType' object has no attribute '__name__'

Do not prettify the soup

In the on_post_page hook, you return a prettified version of the HTML soup:
https://github.com/fralau/mkdocs-mermaid2-plugin/blob/master/mermaid2/plugin.py#L200

It actually changes how the HTML is rendered for the whole page, including elements from other plugins.

Non-prettified:

<code class="highlight language-python">
filter_config<span class="p">(</span><span class="n">data</span><span class="p">)</span> </code>

Screenshot_2020-09-04_13-28-12

Prettifed:

<code class="highlight language-python">
             filter_config
             <span class="p">
              (
             </span>
             <span class="n">
              data
             </span>
             <span class="p">
              )
             </span>
            </code>

Screenshot_2020-09-04_13-27-39

The solution here would be not to prettify the HTML 🙂

By default, mermaid2 works only with the material theme

Issue #11 showed that the mermaid2 plugin works ("out of the box") only with the material theme.

This was documented in version 0.4.2, but this is not ideal for the "ease of use" of the plugin.

As @kerrerain mentioned:

As a user, it might feel easier to not bother with the pymdownx.superfences block in the configuration file. I don't know. There might be another easier solution. For the moment, as long as it is mentioned in the documentation, there's a working solution available. So, this very issue is solved but there might be an improvement possible.

pymdownx.superfences prevents HTML from being interpreted in diagrams

Hyperlinks, bold, etc. in diagrams stop working, when superfences are activated according to instructions.

This issue occurs when all conditions are satisfied:

  1. Loose mode activated (allow HTML to be interpreted in diagrams).
  2. pymdownx.superfences is activated.

In mkdocs.yml:

plugins:
  - ...
  - mermaid2:
      arguments:
        securityLevel: 'loose'

markdown_extensions:
  - ...
  - ...
  - pymdownx.superfences:
      # make exceptions to highlighting of code:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:pymdownx.superfences.fence_div_format

Toggle between dark and light palette doesn't work

Toggle:
mkdocs.yml

- mermaid2:
      arguments:
        # test if its __palette_1 (dark) or __palette_2 (light)
        theme: |
          ^(JSON.parse(window.localStorage.getItem(__prefix('__palette'))).index == 1) ? 'dark' : 'light''

docs/extra/refresh_on_toggle_dark_light.js

var paletteSwitcher1 = document.getElementById("__palette_1");
var paletteSwitcher2 = document.getElementById("__palette_2");

paletteSwitcher1.addEventListener("change", function () {
  location.reload();
});

paletteSwitcher2.addEventListener("change", function () {
  location.reload();
});

does not work with package versions:
pip freeze:

attrs==20.3.0
beautifulsoup4==4.10.0
certifi==2021.10.8
chardet==4.0.0
charset-normalizer==2.0.9
click==8.0.3
EditorConfig==0.12.3
ghp-import==2.0.2
idna==2.10
importlib-metadata==4.8.2
Jinja2==3.0.3
jsbeautifier==1.14.0
Markdown==3.3.6
MarkupSafe==2.0.1
mdx-truly-sane-lists==1.2
mergedeep==1.3.4
mkdocs==1.2.3
mkdocs-altlink-plugin==1.0.1
mkdocs-autolinks-plugin==0.4.0
mkdocs-markmap==2.2.0
mkdocs-material==8.0.5
mkdocs-material-extensions==1.0.3
mkdocs-mermaid2-plugin==0.5.2
mkdocs-roamlinks-plugin==0.1.3
packaging==21.3
Pygments==2.10.0
pymdown-extensions==9.1
pyparsing==3.0.6
python-dateutil==2.8.2
PyYAML==6.0
pyyaml_env_tag==0.1
requests==2.25.1
six==1.16.0
soupsieve==2.3.1
urllib3==1.26.7
watchdog==2.1.6
zipp==3.6.0

Cache check whether library URL exists slow down build

Hi,

first, thanks for this plugin!

I noticed that my total build times increased significantly after adding this plugin (went from 5s to 20s). Upon further inspection I noticed that the code checks whether the JavaScript library exists at the configured URL by sending a HTTP request on every page although the library URL does not change.

Caching the URL check did show a very nice performance boost and brought build time down to 6s, so I propose to implement caching for this.

Text not fitting in the C4 models

Current setup

python 3.10.5

kdocs-git-authors-plugin 0.6.4 Mkdocs plugin to display git authors of a page
mkdocs-git-committers-plugin-2 0.4.3 An MkDocs plugin to create a list of contributors on the page
mkdocs-git-revision-date-localized-plugin 1.0.1 Mkdocs plugin that enables displaying the localized date of the last git modification of a markdown file.
mkdocs-markdownextradata-plugin 0.2.5 A MkDocs plugin that injects the mkdocs.yml extra variables into the markdown template
mkdocs-material 8.3.8 Documentation that simply works
mkdocs-material-extensions 1.0.3 Extension pack for Python Markdown.
mkdocs-mermaid2-plugin 0.5.2 A MkDocs plugin for including mermaid graphs in markdown sources
mkdocs-minify-plugin 0.5.0
pymdown-extensions 9.5 Extension pack for Python Markdown.

mkdocs extensions

theme:
  name: material
...
markdown_extensions:
  - toc:
      permalink: true
  - mdx_include:
      base_path: docs
  - admonition
  - codehilite
  - extra
  - meta
  - attr_list
  - md_in_html
  - pymdownx.details
  - pymdownx.tabbed:
      alternate_style: true
  - def_list
  - footnotes
  - tables
  - pymdownx.tasklist:
      custom_checkbox: true
  - pymdownx.superfences:
      custom_fences:
        - name: mermaid
          class: mermaid
          format: !!python/name:mermaid2.fence_mermaid_custom
  - pymdownx.tabbed
  - pymdownx.emoji:
      emoji_index: !!python/name:materialx.emoji.twemoji
      emoji_generator: !!python/name:materialx.emoji.to_svg

...
extra_javascript:
  - https://unpkg.com/mermaid/dist/mermaid.min.js

I am not sure this is the right place to ask about this, it may be an issue with mkdocs-material directly.

I am trying to show a C4 container

```mermaid
C4Container
    title Container diagram for Dashboard System
    Container_Boundary(a "System") {
        Container(API, "API", "FastAPI", "Provides functionalities to execute operations with HTTP requests")
        Container(Frontend, "Frontend", "HTML/CSS/Js", "Provides functionalities to execute operations with visual aid")
        ContainerDb_Ext(time_serie_db, "Robot collected data", "AWS", "Store data")
    }

And this is what is show
image

As you can see, the text does not fit in the box. On a bigger monitor, it's a bit better for some reasons...
image

Is there an easy way to add some space between the text and box? or another workaround?
Thanks

no <script> mermaid.initialize(...) </script> in generated pages

I just now installed the plugin to MkDocs using pip, so I'm assuming I'm using the latest version.

When starting MkDocs serve, I can see that MERMAID2 is reading my configuration and parsing things like initialization arguments. However. the generated page does not contain:

<script>
mermaid.initialize(...)
</script>

I don't think i'm doing anything wrong....

My mkdocs.yml

site_name: x
nav: 
  - Home: 
theme: material
plugins:
  - search
  - mermaid2:
      arguments:
        theme: 'dark'
extra_javascript:
  - https://unpkg.com/[email protected]/dist/mermaid.min.js

I added the theme dark there to see whether it would trigger the generationg of mermaid.initialize(). Also I tried the exact version of the mermaid.js that was mentioned in the installation documentatoin.

Asynchronous messages in sequence diagrams not supported

First of all, thanks for this great work and this fabulous plugin for mkdocs!

To make it even better, I wanted to report an issue that I encountered:
The plugin seems to have some trouble to display asynchronous messages in mermaid sequence diagrams.

Asynchronous messages are described at https://mermaid-js.github.io/mermaid/#/sequenceDiagram?id=messages in the table. When I try to include an asynchronous message, the rendered diagram breaks down. Instead of the diagram, a syntax error message is displayed.

This might be due to the fact that the newest version of mermaid is 8.12.1 (as of September) and the plugin seems to use mermaid 8.8.0. At least that's the version number provided in the syntax error message displayed instead of the diagram.
I am not sure, when the notation of asynchronous messages was introduced and whether is is already supported by version 8.8.0.

Best regards,
Max

sequenceDiagram brokens

Hello i have next diagrams :

sequenceDiagram
    actor user as manager
    participant api as professions
    participant db as database


    user ->> api: api
    api ->> db: db
    db -->> api: echo
    api -->> user: resp 
Loading

i try use this plugins and i get errors:
image

my config : 
site_name: api-docs
nav:
  - Home: 'service/main.md'
  - arch: 'service/architecture/arch.md'
  - scheme: 'service/scheme/scheme.md'
  - api: 'service/sequences/main.md'
plugins:
  - mermaid2

Support switch between light and dark theme

Could you consider switching the mermaid theme as you choose the light and dark theme by the button on the top bar of material-mkdocs?

Choosing the theme works well depending on the user's environment (I tested both mobile and desktop), however the theme is not changed when the user makes the manual selection. It just follows the default user environment theme.

This means that the light and dark themes work fine according to the documentation, but do not switch when the user selects the button.

So, for example, when the user has the light theme by default but decides to see the mermaid designs in the dark theme, the designs do not appear correctly.

default-light

default-light-choose-dark

default-dark-mobile

default-dark-choose-light-mobile

Collapsed admonitions does not display mermaid properly

Do not know if this problem is in this plugin or in admonitions. But collapsible admonitions (that are already closed) only shows a small rectangle.

!!! note "This Works
    ```mermaid
    graph TD
    A[Client] --> B[Load Balancer]
    ```
???+ note "This Also"
    ```mermaid
    graph TD
    A[Client] --> B[Load Balancer]
    ```
??? note "But not this"
    ```mermaid
    graph TD
    A[Client] --> B[Load Balancer]
    ```

HTML output

I'm no expert in HTML, but I believe the main problem is the size.
Output for the two last examples:

<svg id="mermaid-1597753460847" width="187.546875" xmlns="http://www.w3.org/2000/svg" height="181" viewBox="0 0 187.546875 181">
<svg id="mermaid-1597753460911" width="16" xmlns="http://www.w3.org/2000/svg" height="16" viewBox="-8 -8 16 16">

PS: Tried this with the original plugin and it didn't work.

Can not get bootstrap.min.js.map

I tried to use this plugin in my mkdocs project.
However, I keep getting this 404 GET /js/bootstrap.min.js.map and I don't know how to address it.
Is there possible solutipn? Thank you!

INFO    -  Running task: builder (delay: None)
INFO    -  Building documentation...
[MERMAID] Initialization arguments: {}
[MERMAID] Explicit mermaid javascript library:
   https://unpkg.com/mermaid/dist/mermaid.min.js
[MERMAID] Page 'focus': found 1 (using <pre><code='mermaid'> marker) 
[I 200927 11:18:26 handlers:95] Reload 1 waiters: D:\tpchris1\programming\ATE\sync\Focus_Docs\mkdocs.yml
INFO    -  Reload 1 waiters: D:\tpchris1\programming\ATE\sync\Focus_Docs\mkdocs.yml
[W 200927 11:18:26 web:2246] 404 GET /js/bootstrap.min.js.map (127.0.0.1) 4.99ms
WARNING -  404 GET /js/bootstrap.min.js.map (127.0.0.1) 4.99ms
[I 200927 11:18:27 handlers:135] Browser Connected: http://127.0.0.1:8000/
INFO    -  Browser Connected: http://127.0.0.1:8000/

Skip parsing of HTML pages when possible

Currently every page passed through the post_page event is parsed, while there could be ways to quickly skip it if there are no charts to process.

The optimization proposed in #41 should greatly benefit large documentations with limited use of this plugin.
It does not run BeautifulSoup on every pages produced by mkdocs and instead checks first for the word mermaid textually.
This change allowed a 600 pages documentation (only 1 page with charts) to build in 60s instead of 240s, as about 70% of the total computing time was spent in mermaid's post_page event.

This PR should not have any meaningful consequences on the generated files, except for the fact that pages not processed by mermaid will not be reformatted by bs4 (white lines, indentation and attributes re-ordering). This is probably not an issue since it was mostly a side-effect and actually means keeping the output format of base mkdocs.

Three possibilities:

  • Page with charts: no changes in performance or output
  • Pages with the word mermaid but no charts: no changes in performance or output, some computing time still "wasted"
  • Pages without the word mermaid: much faster processing but output format changed

Font Awesome icons not loading

Hi, thanks for building this great plugin :)

Is it still in active development?

I just started exploring the MkDocs & Mermaid space and was going through the Mermaid documentation.
Here I read how to use font awesome icons.

So I build the following diagram:

graph TD
    A((Data sources))-->B[fa:fa-filter Data collector]
    B-->D[fa:fa-bars Data catalog]

    B-->C[fa:fa-cogs Geo-time engine]
    C-->E[fa:fa-database Data warehouse]
    E-->F[fa:fa-calculator Analytics engine]
    F-->F1[Search/Analytics jobs]
    F1-->G[fa:fa-plug API]
    G-->H[fa:fa-calendar Task manager]
    H-->B
    click E "https://www.cockroachlabs.com/product/" "CockroachDB"
    click F "https://spark.apache.org/" "Apache Spark"
    click G "https://fastapi.tiangolo.com/" "FastAPI"
    click H "https://www.prefect.io/" "Prefect.io"

I got it working in VSCode with this extension, so I know that I got the syntax right.

But it's not loading the font awesome icons when I deploy it with MkDocs. There is a similar issue on the Mermaid GitHub. But it didn't really have a solution. I was wondering if this might be added to this plugin, or if you would know a way to get it working (can be hacky) :)

Thanks a lot!

Error with mkdocs-material

Not sure if it is compatibility issue with mkdocs-material (https://squidfunk.github.io/mkdocs-material/) or error with version 1.1.2.

I added mermaid2 to plugins but getting the following on mkdocs serve.

Config value: 'markdown_extensions'. Error: Failed to initiate extension 'mermaid2': module 'mermaid2' has no attribute 'makeExtension' 
Requirement already satisfied: mkdocs>=1.0.4 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs-mermaid2-plugin) (1.1.2)
Requirement already satisfied: setuptools>=18.5 in /usr/lib/python3/dist-packages (from mkdocs-mermaid2-plugin) (45.2.0)
Collecting soupsieve>1.2
  Downloading soupsieve-2.0.1-py3-none-any.whl (32 kB)
Requirement already satisfied: Jinja2>=2.10.1 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (2.11.2)
Requirement already satisfied: livereload>=2.5.1 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (2.6.1)
Requirement already satisfied: PyYAML>=3.10 in /usr/lib/python3/dist-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (5.3.1)
Requirement already satisfied: click>=3.3 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (7.1.2)
Requirement already satisfied: lunr[languages]==0.5.8 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (0.5.8)
Requirement already satisfied: Markdown>=3.2.1 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (3.2.2)
Requirement already satisfied: tornado>=5.0 in /home/dilawars/.local/lib/python3.8/site-packages (from mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (6.0.4)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10.1->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (1.1.0)
Requirement already satisfied: six in /usr/lib/python3/dist-packages (from livereload>=2.5.1->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (1.14.0)
Requirement already satisfied: future>=0.16.0 in /home/dilawars/.local/lib/python3.8/site-packages (from lunr[languages]==0.5.8->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (0.18.2)
Requirement already satisfied: nltk>=3.2.5; python_version > "2.7" and extra == "languages" in /home/dilawars/.local/lib/python3.8/site-packages (from lunr[languages]==0.5.8->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (3.5)
Requirement already satisfied: tqdm in /home/dilawars/.local/lib/python3.8/site-packages (from nltk>=3.2.5; python_version > "2.7" and extra == "languages"->lunr[languages]==0.5.8->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (4.46.0)
Requirement already satisfied: regex in /home/dilawars/.local/lib/python3.8/site-packages (from nltk>=3.2.5; python_version > "2.7" and extra == "languages"->lunr[languages]==0.5.8->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (2020.4.4)
Requirement already satisfied: joblib in /home/dilawars/.local/lib/python3.8/site-packages (from nltk>=3.2.5; python_version > "2.7" and extra == "languages"->lunr[languages]==0.5.8->mkdocs>=1.0.4->mkdocs-mermaid2-plugin) (0.15.1)
Installing collected packages: soupsieve, beautifulsoup4, mkdocs-mermaid2-plugin
Successfully installed beautifulsoup4-4.9.1 mkdocs-mermaid2-plugin-0.1.5.post1 soupsieve-2.0.1

❓Translation of Diagram Labels

Is there a way to configure several translations (like English, French, and Spanish...) for the labels of a Mermaid diagram?
For instance, I would like to be able to translate the labels for actor, participant, message text, note content, loop, alt, `opt...

I did not find out how to configure this in the static configuration.

Would someone have some clues on how to do this?

mermaid 10 is incompatible

the documentation says you can use the latest version.

https://github.com/fralau/mkdocs-mermaid2-plugin#explicit-declaration-of-the-mermaid-library "For the latest version:"

this is no longer true. 10.0.0 introduces a breaking change, and the min.js file is no longer available (ESM only).

unfortunately unpkg recognizes the new version, and redirects to it. but the file itself is missing.

https://unpkg.com/mermaid/dist/mermaid.min.js -> 302 to 10.0.0

https://unpkg.com/[email protected]/dist/mermaid.min.js -> 404

maybe it would be worthwhile to remove this from the doc, or even add an explicit warning not to omit the version.

Support for sequenceDiagram

When I'm trying to use sequenceDiagram from mermaid I'm getting "Syntax error in graph mermaid version 8.8.0"

Example diagram from mermaid github

sequenceDiagram
    Alice->>John: Hello John, how are you?
    John-->>Alice: Great!
    Alice-)John: See you later!

My setup from mkdocs

  - mermaid2:
      arguments:
        securityLevel: 'loose'
        theme: |
          ^(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light'

use mkdocs-mermaid2-plugin in airgapped systems

Hello,

I'm trying to use mkdocs-mermaid2-plugin in an air-gapped system and I get errors because the plugin is trying to download from the internet https://unpkg.com/[email protected]/dist/mermaid.min.js.

I tried to save the content of https://unpkg.com/[email protected]/dist/mermaid.min.js in a local mermaid.min.js file but unfortunately, if I pass it in this way:

extra_javascript:
  - /full/path/mermaid.min.js

the website will be published but without the proper image display:

$ mkdocs build
INFO     -  MERMAID2  - Initialization arguments: {}
INFO     -  MERMAID2  - Explicit mermaid javascript library:
   ./mermaid.min.js
INFO     -  Cleaning site directory
INFO     -  Building documentation to directory: /builds/nico.oppido/calculator/site
INFO     -  MERMAID2  - Page 'Calculation Docs': found 1 diagrams (with <pre><code='[language-]mermaid'>), converting to <div>...
INFO     -  MERMAID2  - Page 'Calculation Docs': found 1 diagrams, adding scripts
INFO     -  Documentation built in 0.43 seconds

image

I'm using python:3.10-buster with these requirements:

certifi==2022.12.7
charset-normalizer==2.1.1
click==8.1.3
colorama==0.4.6
ghp-import==2.1.0
griffe==0.24.1
idna==3.4
Jinja2==3.1.2
Markdown==3.3.7
MarkupSafe==2.1.1
mergedeep==1.3.4
mkdocs==1.4.2
mkdocs-autorefs==0.4.1
mkdocs-material==8.5.11
mkdocs-material-extensions==1.1.1
mkdocs-mermaid2-plugin==0.6.0
mkdocstrings==0.19.0
mkdocstrings-python==0.8.2
packaging==22.0
Pygments==2.13.0
pymdown-extensions==9.9
python-dateutil==2.8.2
PyYAML==6.0
pyyaml_env_tag==0.1
requests==2.28.1
six==1.16.0
urllib3==1.26.13
watchdog==2.2.0

Can someone help me with the air-gapped scenario?

How to signal an incorrect diagram directly into the html page?

Currently, an incorrect diagram causes the plugin to fail silently. The HTML page will be displayed as if the diagram did not exist. This can be confusing.

It would be preferable that the HTML page displayed an error such as Syntax Error, as is the case with the Mermaid live editor (see example in Mermaid live editor)

Mermaid Live Editor, syntax error

Solutions?

Perhaps one way to achieve that, would be to add info to the Mermaid Configuration argument (json).

Or some javascript snippet?

Is there someone out there who has sufficient experience with the mermaid javascript library, who could orient us toward a simple and reliable situation?

Support Mermaid's callback configuration

Mermaid has the ability (see src/mermaid.js) to invoke a user-configured callback function as it renders each diagram:

mermaid.initialize({
  startOnLoad: true,
  mermaid: {
    callback: function(id) {
      // ...
    },
  },
});

This is invaluable for doing any number of things on Mermaid diagrams that simply cannot be done with CSS.

Right now, I don't see any way to configure a Mermaid callback function in this plugin. Could that be supported in the plugin configuration? The obvious way would seem to be as follows:

plugins:
  - mermaid2:
      arguments:
        theme: neutral
      callback: myMermaidCallbackFunction

mermaid diagram not rendering with 0.6.0

I am using the below content in md file

Flow Chart

	graph TD
	A[Client] --> B[Load Balancer]
	B --> C[Server01]
	B --> D[Server02]
Loading

and below in mkdocs.yaml
plugins:

  • techdocs-core
  • mermaid2
  • multirepo

The latest plugin is installed which is 0.6.0

it doesn't render it

graph TD
A[Client] --> B[Load Balancer]
B --> C[Server01]
B --> D[Server02]

Plug onto mkdocs' logging system

In order to respect mkdocs's strict, verbose and quiet options, you should plug your logging onto mkdocs's.

Here's how you can achieve that:

from mkdocs.utils import warning_filter

log = logging.getLogger(f"mkdocs.plugins.{__name__}")
log.addFilter(warning_filter)

Also see mkdocs/mkdocs#2082

Links not working

Great plugin! Please can you help me enable links in my charts.

I am using your example graph below but the link isn't working on my site. I have the following configuration and everything else is working fine.

plugins:
  - search
  - mkdocstrings
  - autorefs
  - mermaid2:
      arguments:
        theme: default
        securityLevel: 'loose'

The graph is:

graph LR
    hello --> world
    world --> mermaid[mermaid web site]
    click mermaid "https://mermaid-js.github.io/mermaid" "Website"
Loading

I have followed these instructions:

Adding Hyperlinks to a Diagram (versions of Mermaid javascript >~ 8.5.0)
To enable this function, you need to relax mermaid's security level to 'loose'.

Use the click directive in the language (for more information, see Interaction on the official mermaid website)

Custom initialization based on media preferences

It would be great if this mermaidJS plugin could support allowing for a custom initialize block with mkdocs - as mkdocs-material (for example) supports a "preferences" which allows one to automatically switch between light/dark theme. A similar effect can be done with something like

mermaid.initialize({
    theme: (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) ? 'dark' : 'light'
 });

but how does one override the injection of this JS and provide your own?

Support for navigation.instant option of material theme

Hi,

with the navigation.instant option of the material theme enabled no diagrams are rendered, only after reloading a page.

The mathjax part of the documentation ( https://squidfunk.github.io/mkdocs-material/reference/mathjax/ ) actually contains a snippet which seems to be related:

document$.subscribe(() => {
  MathJax.typesetPromise()
})

Maybe something similar is possible for mermaid? The mermaid.initialize(...) snipped probably needs to be tweaked as well since only parts of a page re replaced with the instant navigation option.

Diagrams with <> inside them cause incorrect HTML generation.

I have a mermaid diagram with the following:

graph TD
    a[description.bat <version>]
    b[description.ps1 <version>]
    
    a --> b
Loading

While something like this works on the mermaid.js site, the mkdocs-mermaid2-plugin fails to generate the correct html for this. The HTML generated is:

<div class="mermaid">graph TD
    a[description.bat <version>]
    b[description.ps1 <version>]

    a --&gt; b
</version></version></div>

but it should be:

<div class="mermaid">graph TD
    a[description.bat <version>]
    b[description.ps1 <version>]

    a --&gt; b
</div>

I am using the newest version of this plugin and got this issue with several different versions of mkdocs from the default all the way to 8.10.1.

Superfences custom fence function does not seem to work

Running current version of mkdocs, installed yesterday. Using superfences, and added the declaration so it loads.

Nothing at all shows up if I use mermaid version 10.0.2. If I swap to ANY OTHER VERSION (tried 8.7.0, 8.8.0, and 10.2.4) I get a syntax error, despite trying the code in the online editor with success. I even tried to use the example diagram right off this github readme and it still errors. Any ideas?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.