Giter Site home page Giter Site logo

mgaitan / sphinxcontrib-mermaid Goto Github PK

View Code? Open in Web Editor NEW
311.0 9.0 84.0 123 KB

Mermaid diagrams in yours sphinx powered docs

Home Page: http://sphinxcontrib-mermaid-demo.readthedocs.io/en/latest/

License: Other

Python 100.00%
sphinx-extension sphinxcontrib sphinx-doc uml diagrams

sphinxcontrib-mermaid's Introduction

image

image

image

This extension allows you to embed Mermaid graphs in your documents, including general flowcharts, sequence diagrams, gantt diagrams and more.

It adds a directive to embed mermaid markup. For example:

.. mermaid::

   sequenceDiagram
      participant Alice
      participant Bob
      Alice->John: Hello John, how are you?
      loop Healthcheck
          John->John: Fight against hypochondria
      end
      Note right of John: Rational thoughts <br/>prevail...
      John-->Alice: Great!
      John->Bob: How about you?
      Bob-->John: Jolly good!

By default, the HTML builder will simply render this as a div tag with class="mermaid", injecting the external javascript, css and initialization code to make mermaid works.

For other builders (or if mermaid_output_format config variable is set differently), the extension will use mermaid-cli to render as to a PNG or SVG image, and then used in the proper code.

sequenceDiagram

participant Alice participant Bob Alice->John: Hello John, how are you? loop Healthcheck John->John: Fight against hypochondria end Note right of John: Rational thoughts <br/>prevail... John-->Alice: Great! John->Bob: How about you? Bob-->John: Jolly good!

You can also embed external mermaid files, by giving the file name as an argument to the directive and no additional content:

.. mermaid:: path/to/mermaid-gantt-code.mmd

As for all file references in Sphinx, if the filename is not absolute, it is taken as relative to the source directory.

In addition, you can use mermaid to automatically generate a diagram to show the class inheritance using the directive autoclasstree. It accepts one or more fully qualified names to a class or a module. In the case of a module, all the class found will be included.

Of course, these objects need to be importable to make its diagram.

If an optional attribute :full: is given, it will show the complete hierarchy of each class.

The option :namespace: <value> limits to the base classes that belongs to this namespace. Meanwhile, the flag :strict: only process the classes that are strictly defined in the given module (ignoring classes imported from other modules).

For example:

.. autoclasstree:: sphinx.util.DownloadFiles sphinx.util.ExtensionError
   :full:

sphinx.util.DownloadFiles sphinx.util.ExtensionError

Or directly the module:

.. autoclasstree:: sphinx.util

sphinx.util

Installation

You can install it using pip

pip install sphinxcontrib-mermaid

Then add sphinxcontrib.mermaid in extensions list of your project's conf.py:

extensions = [
    ...,
    'sphinxcontrib.mermaid'
]

Directive options

:alt:: determines the image's alternate text for HTML output. If not given, the alternate text defaults to the mermaid code.

:align:: determines the image's position. Valid options are 'left', 'center', 'right'

:caption:: can be used to give a caption to the diagram.

:zoom:: can be used to enable zooming the diagram. For a global config see mermaid_d3_zoom` bellow.

A preview after adding :zoom: option only to the first diagram example above:

A preview after adding :zoom: option only to the first diagram example above:

Config values

mermaid_output_format

The output format for Mermaid when building HTML files. This must be either 'raw' 'png' or 'svg'; the default is 'raw'. mermaid-cli is required if it's not raw

mermaid_version

The version of mermaid that will be used to parse raw output in HTML files. This should match a version available on https://unpkg.com/browse/mermaid/. The default is "10.2.0". If you need a newer version, you'll need to add the custom initialization. See below.

If it's set to "", the lib won't be automatically included from the CDN service and you'll need to add it as a local file in html_js_files. For instance, if you download the lib to _static/js/mermaid.js, in conf.py:

html_js_files = [
   'js/mermaid.js',
]

mermaid_init_js

Mermaid initilizaction code. Default to "mermaid.initialize({startOnLoad:true});".

0.7 The init code doesn't include the <script> tag anymore. It's automatically added at build time.

mermaid_cmd

The command name with which to invoke mermaid-cli program. The default is 'mmdc'; you may need to set this to a full path if it's not in the executable search path.

mermaid_cmd_shell

When set to true, the shell=True argument will be passed the process execution command. This allows commands other than binary executables to be executed on Windows. The default is false.

mermaid_params

For individual parameters, a list of parameters can be added. Refer to https://github.com/mermaidjs/mermaid.cli#options. Examples:

mermaid_params = ['--theme', 'forest', '--width', '600', '--backgroundColor', 'transparent']

This will render the mermaid diagram with theme forest, 600px width and transparent background.

mermaid_sequence_config

Allows overriding the sequence diagram configuration. It could be useful to increase the width between actors. It needs to be a json file Check options in the documentation

mermaid_verbose

Use the verbose mode when call mermaid-cli, and show its output in the building process.

mermaid_pdfcrop

If using latex output, it might be useful to crop the pdf just to the needed space. For this, pdfcrop can be used. State binary name to use this extra function.

mermaid_d3_zoom

Enables zooming in all the generated Mermaid diagrams.

Markdown support

You can include Mermaid diagrams in your Markdown documents in Sphinx. You just need to setup the markdown support in Sphinx via myst-parser . See a minimal configuration from the tests

Then in your .md documents include a code block as in reStructuredTexts:

```{mermaid}

    sequenceDiagram
      participant Alice
      participant Bob
      Alice->John: Hello John, how are you?
```

Building PDFs on readthedocs.io

In order to have Mermaid diagrams build properly in PDFs generated on readthedocs.io, you will need a few extra configurations.

  1. In your .readthedocs.yaml file (which should be in the root of your repository) include a post-install command to install the Mermaid CLI: :

    build:
      os: ubuntu-20.04
      tools:
        python: "3.8"
        nodejs: "16"
      jobs:
        post_install:
          - npm install -g @mermaid-js/mermaid-cli

Note that if you previously did not have a .readthedocs.yaml file, you will also need to specify all targets you wish to build and other basic configuration options. A minimal example of a complete file is: :

# .readthedocs.yaml
# Read the Docs configuration file
# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details

# Required
version: 2

# Set the version of Python and other tools you might need
build:
  os: ubuntu-20.04
  apt_packages:
    - libasound2
  tools:
    python: "3.8"
    nodejs: "16"
  jobs:
    post_install:
      - npm install -g @mermaid-js/mermaid-cli

# Build documentation in the docs/ directory with Sphinx
sphinx:
   configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
formats:
  - epub
  - pdf

python:
   install:
   - requirements: docs/requirements.txt
  1. In your documentation directory add file puppeteer-config.json with contents: :

    {
      "args": ["--no-sandbox"]
    }
  2. In your documentation conf.py file, add: :

    mermaid_params = ['-p' 'puppeteer-config.json']

sphinxcontrib-mermaid's People

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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sphinxcontrib-mermaid's Issues

Changing custom classes /themes is ignored

I have the following diagram:

.. mermaid::
  :caption: Diagrama de metodología
  :alt: Diagrama de metodología
  :align: center


  graph TD
    A(Building Part)--PBAbp-->PBA_inici
    B(Cadastral Parcel)--PBAcp-->PBA_inici
    C(Working Area)--"(Nombre de capa varia)"-->PBA_inici
    PBA_inici[PBA_inici]--PBbpcp-->PB_topologia[PB_topologia]
    PBA_inici[PBA_inici]-.PBbp_selected.->Backup>Capas de Backup]
    PBA_inici[PBA_inici]-.PBcp_selected.->Backup>Capas de Backup]
    subgraph Topologia
      PB_topologia[PB_topologia]--PBAr-->Rev_top[Revision topologia manual]
      click PB_topologia "#revision-topologica" "Ver info detallada"
    end
    subgraph Orientaciones
      Rev_top--"Checked_PBAr"-->Pol2Line[Modelo Pol2Line]

    end
    classDef BackupLayers fill:#e7bbbb,stroke:#880000,stroke-width:1px
    class Backup BackupLayers
    classDef Models fill:#bbe7e2,stroke:#008878
    class PBA_inici,PB_topologia Models

The expected result would be that from mermaid online editor (see link)

Expected result

But instead, I get the following one, which ignores my custom classes:

Actual result, ignoring custom classes

Furthermore, I would like to use the neutral built-in theme, but despite the readme file states that it is possible using mermaid_params, I do not know where and how should I pass the theme parameter so mermaid is built when building a sphinx page.

share the conflict with the other sphinx extensions

nbsphinx and sphinxcontrib-mermaid are conflict

sphinxcontrib-mermaid need https://unpkg.com/mermaid/dist/mermaid.min.js

nbsphinx need https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.4/require.min.js

put together not work

syntax error with python2.7 - windows 10

I ran into mermaid. It s the perfect plugin i need for my sphinx documentation API.
I installed the contribution on my windows 10 - python 2.7
when i ran a simple example, this exception appears

`Running Sphinx v1.8.5

Exception occurred:
File "c:\users\fleboeuf\miniconda3\envs\pycgm2\lib\site-packages\sphinxcontrib\mermaid.py", line 33, in
from .autoclassdiag import class_diagram
File "c:\users\fleboeuf\miniconda3\envs\pycgm2\lib\site-packages\sphinxcontrib\autoclassdiag.py", line 6
def get_classes(*cls_or_modules, strict=False):
^
SyntaxError: invalid syntax`

could you help me to fix it please ?

regards

Fabien

Umlauts causing error on build

Umlauts, as common in German Language (like: ä, ö, ü) causing problems buildung Sphinx Docs. The infected Charts are replaced by "Syntax error in graph mermaid version 8.13.7":

Error Message displayed in Doc:
Error

As soon as all umlauts are replaced, the graphs will be displayed as expected.
Tested make commands: html, latexpdf

Example:

`.. mermaid::

flowchart LR
a(Kundeninput) --> b(Product-Backlog) --> c(Sprintplanung) --> e("Sprint (2-4 Wochen)") --> f(Sprint-Review) --> g([Zum Veröffentlichungsprozess])
e --> d(Sprint-Retrospektive) --> c`

When I build the mermaid chart with mermaid-cli the umlauts are built correct (see output.png below):
output

used version: Master (a6c1f8b)

sphinxcontrib-mermaid uses six but doesn't explicitly require it.

Our docs project dropped py2 support so we no longer reference six. But when we attempt to build the docs, loading sphinxcontrib.mermaid fails because six is missing.

docs run-test: commands[0] | sphinx-build -a -E -W -d doc/build/doctrees --keep-going -b html doc/source doc/build/html
setting PATH=/home/zuul/src/opendev.org/openstack/tripleo-docs/.tox/docs/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
[4294] /home/zuul/src/opendev.org/openstack/tripleo-docs$ /home/zuul/src/opendev.org/openstack/tripleo-docs/.tox/docs/bin/sphinx-build -a -E -W -d doc/build/doctrees --keep-going -b html doc/source doc/build/html
Running Sphinx v3.3.1

Extension error:
Could not import extension sphinxcontrib.mermaid (exception: No module named 'six')

Fails after 0.6.1 update

Link: wemake-services/wemake-python-styleguide#1859
Job: https://readthedocs.org/projects/wemake-python-styleguide/builds/12971370/

Traceback:

Traceback (most recent call last):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/cmd/build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/application.py", line 352, in build
    self.builder.build_update()
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 298, in build_update
    len(to_build))
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 360, in build
    self.write(docnames, list(updated_docnames), method)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 534, in write
    self._write_serial(sorted(docnames))
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 544, in _write_serial
    self.write_doc(docname, doctree)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/builders/html/__init__.py", line 597, in write_doc
    self.docwriter.write(doctree, destination)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/docutils/writers/__init__.py", line 78, in write
    self.translate()
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/writers/html.py", line 71, in translate
    self.document.walkabout(visitor)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/docutils/nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/docutils/nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/docutils/nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/docutils/nodes.py", line 206, in walkabout
    visitor.dispatch_visit(self)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/util/docutils.py", line 468, in dispatch_visit
    method(node)
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinxcontrib/mermaid.py", line 267, in html_visit_mermaid
    render_mm_html(self, node, node['code'], node['options'])
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinxcontrib/mermaid.py", line 228, in render_mm_html
    _fmt = self.builder.config.mermaid_output__fmt
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/config.py", line 257, in __getattr__
    raise AttributeError(__('No such config value: %s') % name)
AttributeError: No such config value: mermaid_output__fmt

Exception occurred:
  File "/home/docs/checkouts/readthedocs.org/user_builds/wemake-python-styleguide/envs/1859/lib/python3.7/site-packages/sphinx/config.py", line 257, in __getattr__
    raise AttributeError(__('No such config value: %s') % name)
AttributeError: No such config value: mermaid_output__fmt

Unable to use mermaid.cli on Windows 10

Hi there,

I have a simple Sphinx project where I'd like to be able to render my Mermaid charts as png. To do so, I have installed the mermaid.cli via yarn, but I've not managed to get it to work.

My attempts

I've tried various combinations:

  • I've tried installing globally via npm and yarn, to no luck
  • I've tried to install locally in the root folder of my Sphinx project and referring to the .bin folder as an absolute path in my conf.py - but to no luck
  • I am able to use the mmdc from the command prompt as normal

My conf.py

My conf.py is located at C:\Users\marti\Documents\sphinx-test\docs and contains the below (amongst other things):

extensions = [
    "sphinxcontrib.mermaid",
]

mermaid_cmd = "C:\\Users\\marti\\Documents\\sphinx-test\\node_modules\\.bin\\mmdc"
mermaid_output_format = "png"

The traceback

When I use the above conf.py I get below traceback. If I remove \\mmdc from the path, I instead get a Permission Denied error.

# Sphinx version: 3.0.0
# Python version: 3.7.3 (CPython)
# Docutils version: 0.14 
# Jinja2 version: 2.11.1
# Last messages:
#   none found
#   pickling environment...
#   done
#   checking consistency...
#   done
#   preparing documents...
#   done
#   writing output... [ 33%] configure/configure
#   writing output... [ 66%] index
#   writing output... [100%] introduction/introduction
# Loaded extensions:
#   sphinx.ext.mathjax (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\mathjax.py
#   sphinxcontrib.applehelp (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\applehelp\__init__.py
#   sphinxcontrib.devhelp (1.0.2) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\devhelp\__init__.py
#   sphinxcontrib.htmlhelp (1.0.3) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\htmlhelp\__init__.py
#   sphinxcontrib.serializinghtml (1.1.4) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\serializinghtml\__init__.py
#   sphinxcontrib.qthelp (1.0.3) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\qthelp\__init__.py
#   alabaster (0.7.12) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\alabaster\__init__.py
#   recommonmark (0.6.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\recommonmark\__init__.py
#   sphinx.ext.todo (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\todo.py
#   sphinx.ext.githubpages (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\ext\githubpages.py
#   sphinxcontrib.mermaid (3.0.0) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py
#   romnnn_sphinx_press_theme (unknown version) from c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\romnnn_sphinx_press_theme\__init__.py
Traceback (most recent call last):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\cmd\build.py", line 280, in build_main
    app.build(args.force_all, filenames)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\application.py", line 348, in build
    self.builder.build_update()
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 299, in build_update
    len(to_build))
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 361, in build
    self.write(docnames, list(updated_docnames), method)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 535, in write
    self._write_serial(sorted(docnames))
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\__init__.py", line 545, in _write_serial
    self.write_doc(docname, doctree)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\builders\html\__init__.py", line 597, in write_doc
    self.docwriter.write(doctree, destination)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\writers\__init__.py", line 80, in write
    self.translate()
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\writers\html.py", line 71, in translate
    self.document.walkabout(visitor)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 174, in walkabout
    if child.walkabout(visitor):
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\docutils\nodes.py", line 166, in walkabout
    visitor.dispatch_visit(self)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinx\util\docutils.py", line 468, in dispatch_visit
    method(node)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 280, in html_visit_mermaid
    render_mm_html(self, node, node['code'], node['options'])
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 251, in render_mm_html
    fname, outfn = render_mm(self, code, options, format, prefix)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\site-packages\sphinxcontrib\mermaid.py", line 182, in render_mm
    p = Popen(mm_args, stdout=PIPE, stdin=PIPE, stderr=PIPE)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\subprocess.py", line 775, in __init__
    restore_signals, start_new_session)
  File "c:\users\marti\appdata\local\programs\python\python37\lib\subprocess.py", line 1178, in _execute_child
    startupinfo)
OSError: [WinError 193] %1 is not a valid Win32 application

Any help would be greatly appreciated.

Much duplicate sourcing of JS

I'm seeing many duplicates of <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script> in rendered output e.g. https://docs.hpc.shef.ac.uk/en/latest/hpc/hpcgateway.html.

Info on my environment:

$ pip freeze | grep sphinx
sphinx-autobuild==0.7.1
sphinx-bootstrap-theme==0.4.14
sphinx-rtd-theme==0.5.1
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-mermaid==0.6.3
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4

Render using inline mermaid on HTML

currently, the conversion uses mermaid-cli as an "external tool". This require to set up the command via node.
Alternatively, mermaid works as an standard library that can be included directly in the html page.

Check

http://knsv.github.io/mermaid/#simple-usage-on-a-web-page
http://www.sphinx-doc.org/es/stable/extdev/appapi.html#sphinx.application.Sphinx.add_stylesheet
http://www.sphinx-doc.org/es/stable/extdev/appapi.html#sphinx.application.Sphinx.add_javascript

PDF generation fails with latest Sphinx

Sphinx has changed the logging object somewhat, so we get unexpected breakage when the plugin calls "self.builder.warn()". This breaks latexpdf output though:

Exception occurred:
File "/[REDACTED]/lib/python3.6/site-packages/sphinxcontrib/mermaid.py", line 180, in render_mm
self.builder.warn('Mermaid SVG support is experimental')
AttributeError: 'LaTeXBuilder' object has no attribute 'warn'

A fix release would be much appreciated! :)

raises UnicodeEncodeError when code block includes non-ASCII characters

if I used the non-ASCII character in the mermaid code block, sphinx-build raises UnicodeEncodeError.

$ sphinx-build -P -b html -d _build/doctrees . _build/html test.rst
# .. skip logs ..
  File "/home/user/project/env/local/lib/python2.7/site-packages/sphinxcontrib/mermaid.py", line 236, in _render_mm_html
_raw
    self.body.append(tag_template.format(align=node.get('align'), code=self.encode(code)))
UnicodeEncodeError: 'ascii' codec can't encode character u'\ub97c' in position 50: ordinal not in range(128)
[14] > /home/user/project/env/local/lib/python2.7/site-packages/sphinxcontrib/mermaid.py(236)_render_mm_html_raw()
-> self.body.append(tag_template.format(align=node.get('align'), code=self.encode(code)))

here is the test.rst:

.. mermaid::

    sequenceDiagram

    A ->> B: UnicodeEncodeError를 발생시킨다

versions:

$ pip freeze | grep sphinx
sphinx-rtd-theme==0.4.3
sphinxcontrib-httpdomain==1.7.0
sphinxcontrib-mermaid==0.3.1
sphinxcontrib-websupport==1.0.1

$ python --version
Python 2.7.12

# mermaid.py

      if 'align' in node:
          tag_template = """<div align="{align}" class="mermaid align-{align}">
              {code}
          </div>
          """
      else:
          tag_template = """<div class="mermaid">
              {code}
          </div>"""

      self.body.append(tag_template.format(align=node.get('align'), code=self.encode(code)))

The problem is that type of tag_template and code are different.
the type of tag_template is str, but type of self.encode(code) is unicode.

Also, I know that this bug only occurs on Python 2.

Support for the new Mermaid CLI

I just installed this extension and ran into problems immediately. The used mermaid-cli is deprecated and the new official have a completely different syntax.

The official CLI is available from https://github.com/mermaidjs/mermaid.cli and for starters the command is now mmdc instead of mermaid. The output type is determined by the extension of the output file, there are no flags for verbose, phantomPath or sequenceConfig.

I did a short attempt to get it working but my knowledge of Python and Sphinx extensions wasn't really enough. Ideally this could be supported by checking the mermaid_cmd option if we should use mermaid or mmdc to keep it backwards compatible.

New release and update package on PyPi

Since the last release (0.3.1), some significant features including parsing parameters for mermaid.cli have been added. I think it would justify a (minor) release so the current status can simply be downloaded with pip.

Class not working in raw output format

Hi,

I use sphinxcontrib-mermaid to write documentation for my projects that I then publish as HTML. It works quite well, generally better than other tools I have tried, but sometimes I would like to use classes on the nodes in flowcharts, to change the background colour for instance.

Mermaid.js allows to define classes inside a diagram statement with the classDef attribute. Here is an example:

graph TB
  s((Start))
  e((End))
     
  s --> e
     
  classDef Foo fill:#66ccff;
  class s Foo;

This should (at least it does with mermaid.cli) render as :

flowchart

But when using raw output format with sphinxcontrib-mermaid (which is convenient since it does not require to install mermaid.cli), my start node is not colored. I assume that is because the CSS code defining the styling of the class Foo is not included in the HTML page.

I believe a workaround would be to create my own CSS stylesheet, with definitions of my class styles, and configure Sphinx to use it. But it would be great if sphinxcontrib-mermaid could handle the classDef by itself.

issue such command 'mermaid' cannot be run

Hi everyone,

I have installed sphinxcontrib-mermaid extension as the following guide: https://github.com/mgaitan/sphinxcontrib-mermaid

in a "mermaid-template.rst" file I made a code such below

Mermaid Template
#################

.. mermaid::

    graph LR
    A[Hard edge] -->B(Round edge)
        B --> C{Decision}
        C -->|One| D[Result one]
        C -->|Two| E[Result two]

When running sphinx that threw out a warning such below and the flowchart was not generated:

warning: command 'mermaid' cannot be run (needed for mermaid output), check the mermaid_cmd setting.

After that I still installed mermaid-cli as the following guide: https://knsv.github.io/mermaid/#mermaid-cli8

But the warning was still exists and was not generated the flowchart.
May anyone help me in this case?

P.S:

  • OS: window 8.1
  • Sphinx: 1.4.8
  • PhantomJS: 2.1.1
  • Mermaid setup success with command such as mermaid template.mmd or mermaid --help

Thank you for your watching,
Best Regards

Could not import extension sphinxcontrib.mermaid

Hi,

This is my extensions:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.doctest',
'sphinx.ext.intersphinx',
'sphinx.ext.todo',
'sphinx.ext.coverage',
'sphinx.ext.mathjax',
'sphinx.ext.napoleon',
'recommonmark',
'breathe',
'exhale',
'sphinxcontrib.mermaid'
]

but it happens error: Could not import extension sphinxcontrib.mermaid
Any idea?

Ability to use Mermaid API or add a custom JS script

I'm looking to add a custom script after the mermaid diagram renders, similar to the examples shown here. It looks like _render_mm_html_raw() is where this would need to happen. Is there an existing capability to support this, or would this be a new feature?

Whitespace between text and sequence diagram

Hello - this is a great project - thank you for maintaining it!

I'm not sure if this is a known issue (not really finding references to it in the issues or pull requests) and I could very well be doing something wrong (fairly new to sphinx and sphinx extensions in general).

When I add a sequence diagram to a markdown file, there's always a gap of whitespace between the text on the page and the diagram, about the same size as what the instructions take. In addition, when I refresh the page, I see the instructions flash in the whitespace area. (See gif) Is there some configuration step I'm missing or a way to resolve these issues? (The whitespace being more troubling than the flash of instructions.)

MermaidWhitespaceRefreshIssue

Here's the markdown as well: # Example Mermaid Sequence Diagram

Here's an example Mermaid Sequence Diagram. Note the whitespace between this paragraph and the diagram. Also, note how the diagram's instructions are briefly visible on refresh. Is this a known issue?

sequenceDiagram
    participant ModuleA
    participant ModuleB
    participant ModuleC
    participant ModuleD
    participant ModuleE
    participant ModuleF
    Note left of ModuleA: fetch widgets
    ModuleA->>ModuleB: https GET api/widgets
    ModuleB->>ModuleC: https GET api/widgets
    ModuleC-->>ModuleB: api/widgets response
    ModuleB-->>ModuleA: api/widgets response

    Note left of ModuleA: snippet init
    ModuleA->>ModuleB: https POST api/gadgets
    ModuleB->>ModuleC: https POST api/snippets
    ModuleC->>ModuleD: launch_process()
    ModuleD->>ModuleE: launch snippet
    ModuleD->>ModuleF: confirm startup
    ModuleE-->>ModuleD: connection info
    ModuleF-->>ModuleD: state & host info
    ModuleD-->>ModuleC: complete connection info
    ModuleC->>ModuleE: TCP socket requests
    ModuleE-->>ModuleC: TCP socket handshakes
    ModuleC-->>ModuleB: api/snippets response
    ModuleB-->>ModuleA: api/gadgets response

    ModuleA->>ModuleB: ws GET api/snippets
    ModuleB->>ModuleC: ws GET api/snippets
    ModuleC-->>ModuleB: websocket upgrade response
    ModuleB-->>ModuleA: websocket upgrade response

Note: the backticks on the mermaid directive and closing backticks are not showing up. I'm using the myst-parser with a syntax identical to what's on this page.

mermaid_params does not work

Hi,

I added what's from the Readme to my conf.py file:

mermaid_params = ['--theme', 'forest', '--width', '600', '--backgroundColor', 'transparent']

The build works fine, but I still get the default style.
Has anyone experienced the same issue?

Lack of encode() call generates errors in render_mm()

Lack of encode() call generates errors in render_mm()

I'm not sure exactly why, but I get this error when using the new 0.6.0:

  Exception occurred:
    File "C:\Users\Admin\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 958, in _stdin_write
      self.stdin.write(input)
  TypeError: a bytes-like object is required, not 'str'

The root cause stack trace log produced by sphinx leads me to:

...lib\site-packages\sphinxcontrib\mermaid.py", line 191, in render_mm
    stdout, stderr = p.communicate(code)

I believe it is due to the change in this commit linked below, because when I hack in an encode("utf-8") call it works fine again.

6dbbf38#diff-b760861ad44d628f879c0d6e15c71c85ff086c1bbd530a006920c6ab38154ca7L172

For now I will try and revert to 0.5.0 but it would be better if this were fixed :-)

Cross-reference link in mermaid chart

Hi there,

I'm trying to create a cross-reference link inside a mermaid chart in Sphinx, as below. In Jekyll, the syntax would e.g. be click A "configure/". However, I'm not sure how to get this working in Sphinx - is it possible?

.. mermaid::

  graph LR
    A(Configure)
    B(Record)
    C(Transfer)
    D(Process)
    E(Display)
    A-->B
    B-->C
    C-->D
    D-->E
    click A :ref:`configure`

offline JS file

Please, allow to use offline JS file.

Currently the JS's URL is linked to online page and i cannot see way to change it to use offline copy, other than change code. Or i miss something?

Can you please add config value for this? E.g. if unset (default) it will use online URL as now, if set to same path, it will use this path relative to static folder.

Suggestion: automatic class tree for Python libraries

Hey Martin,

I am looking for a way to automatically plot UML diagrams of the inheritance between classes in the Sphinx docs of a library. I think Mermaid would be the classiest solution (everything else looks a bit old) and it seems that this project already solves part of the problem, making Mermaid work with Sphinx.

For the automated class tree generation, I wrote a proof of principle script here. How difficult do you think it would be to turn this into a easy-to-use sphinx tag ? For instance as follows:

.. autoclasstree:
    module: moviepy.editor
    base_module: moviepy

and output the full tree in the final presentation:

result image

include mermaid graph in latexpdf

With this simple test

$ tree
.
├── _build
├── conf.py
├── index.rst
├── Makefile
├── requirements.txt
├── _static
└── _templates
$
$ tail -1 conf.py
extensions = ['sphinxcontrib.mermaid']
$
$ cat index.rst                             
Test mermaid with `sphinx latexpdf`
====================================

Test mermaid with `sphinx latexpdf`

Try to render::

   graph TD
      A --> B --> C --> A

.. mermaid::

   graph TD
      A --> B --> C --> A

Mermaid rendered above ?
$ 
$ make html
...
$ firefox _build/html/index.html
$

Sélection_714

$ make latexpdf
...
$ evince _build/latex/mermaid_test.pdf `
$

Sélection_713

look's like the SVG is not added to the tex file::

$ tail -20 _build/latex/mermaid_test.tex
\pagestyle{normal}
\phantomsection\label{\detokenize{index::doc}}
Test mermaid with \sphinxtitleref{sphinx latexpdf}
Try to render:

\begin{sphinxVerbatim}[commandchars=\\\{\}]
\PYG{n}{graph} \PYG{n}{TD}
   \PYG{n}{A} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{B} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{C} \PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZhy{}}\PYG{o}{\PYGZgt{}} \PYG{n}{A}
\end{sphinxVerbatim}

Mermaid rendered above ?
\renewcommand{\indexname}{Index}
\printindex
\end{document}(venv) 
$

Python 3 compat

Thanks for this great plugin! Since more and more projects are moving forward to Python 3 and Sphinx is also working with py3 now, could we ensure this plugin works with py3 as well?

I'm getting following exception:

Exception occurred:
  File "/Users/daniel/Workspace/zg_ecommerce/lib/python3.5/site-packages/sphinxcontrib/mermaid.py", line 145, in render_mm
    t.write(code)
TypeError: write() argument must be str, not bytes

exception: No module named sphinxcontrib-mermaid

Hi,

First of all, thanks for creating this extension, it's a great initiative.

Unfortunately, I cannot manage to run it.

I get the following error when running make html:

Could not import extension sphinxcontrib-mermaid (exception: No module named sphinxcontrib-mermaid)
make: *** [html] Error 1

I have performed the following prior to running the make file:

  1. pip install sphinxcontrib-mermaid
  2. update the conf.py as needed
  3. npm install -g mermaid
  4. npm install -g phantomjs

Any idea?

Other details:
Sphinx: 1.6.2
OS: MacOS

PDF output?

I was reading through the code as I'm currently writing a mermaid pandoc filter in python, for a LaTeX output, so ideally I need PDF output.

This code seems to have LaTeX support, however, I can't wrap my mind of the internal working of the process.

As I understand it all render_mm_latex does is requesting the 'pdf' format, to render_mm, which will just discard the option altogether and fall back to SVG output, so you'd end up with a file with a .pdf extension but with SVG content.

Then you use this file with an \includegraphics directive, but AFAIK LaTeX doesn't support SVG at all, so it won't work.

Am I missing something?

Show generic arguments

Hi again! 🙂

In my use-case, it is very important to show what generic arguments types have.
Let's see it with real-life example.

This is how my Maybe is show in the new version of this plugin:

Снимок экрана 2020-09-04 в 10 33 29

But, that's how it is defined:

class Maybe(
    BaseContainer,
    SupportsKind1['Maybe', _ValueType],
    MaybeBased2[_ValueType, None],
    metaclass=ABCMeta,
):

See, how many information about typing is lost right now! 😞

I propose to show all available typing information if :generics: key is given.

Here's a quick demo to show that it is possible.

>>> from typing import Generic
>>> from typing import TypeVar
>>> T = TypeVar('T')
>>> class Example(Generic[T]): ...
... 
>>> Example.__mro__
(<class '__main__.Example'>, <class 'typing.Generic'>, <class 'object'>)
>>> Example.__orig_bases__
(typing.Generic[~T],)

Related to #48

Controlling width of mermaid diagram for PDF generation

I'm using this extension in my sphinx project, which works nicely for my html documentation. Here I set the output_format to svg and the charts render nicely.

However, when I render my latex and PDF files, some mermaid charts go out-of-page in terms of width. I would like this to be controlled so that they stay within the bounds.

Is this something that should be done via the mermaid settings - or somewhere else?

I figured it might be related to the width defined of the underlying PNG images, but I've not been able to find a way to control this via the extension.

Similarly, I'm also struggling with how to avoid each mermaid diagram blocking text on the entire page in which they're added.

EDIT: I guess perhaps the issue here is that the mermaid diagrams are rendered as svg despite the use of png as the output format. This causes the mermaid diagrams to be included in my latex output as pdf files, rather than as png (which was what I expected). Note that I am able to render my mermaid diagrams as png when using the html build - so I'm not sure why it does not work for the latex build.

Mermaid version update

Hi -- thanks for your work on the mermaid sphinx bridge! You might consider updating the Mermaid version in mermaid.py to "8.0.0-rc.6". It got bumped a couple of weeks ago, and there are some useful new features (xaxis marks on timelines).

mermaid-js/mermaid#643

Does not fully render `classDiagram` and does not render `sequenceDiagram`

I have the following file:

*********************
Architecture overview
*********************

Class Diagram
#############

.. mermaid::

    classDiagram

    class Device {
        +str name
        +info Tuple[int, int, int]
        +rdescs List[List[int]]
        +report_rate int
        +endpoints List[Endpoint]
        +actuators List[Actuator]
        +hw Dict[str, HWComponent]
        +fw Firmware

        +destroy()
        +transform_action(action) %% Passes the action by the actuators and returns the transformed result ()
        +send_hid_action(action) %% Sends HID action to all endpoints (create_report -> call_input_event)
        +simulate_action(action) %% Transforms high-level action into HID timed events and sends them ()
    }

    class UHIDDevice

    UHIDDevice --|> Endpoint : inherits
    class Endpoint {
        -_owner Device
        -_hid_properties List[HIDProperty]
        +rdesc List[int]
        +name str
        +number int
        +uhid_dev_is_ready bool

        -_update_hid_properties() %% Parses the report descriptor and populates _hid_properties ()
        -_receive(data, size, rtype) %% HID data receive callback (triggers the firmware callback)
        +send(data) %% Sends HID data ()
        +create_report(action, skip_empty) %% Creates a report based on the HID data ()
        +populate_hid_data(action, packets) %% Uses the _hid_properties to populate HID events ()
    }
    Device --> Endpoint : owns

    class Firmware {
        -_owner Device

        +hid_receive(data, size, rtype, endpoint)
        +hid_send(data, endpoint)
    }
    Device --> Firmware : owns

    class Actuator {
        -keys List[str]

        +transforms(action) %% Transform a high-level action ()
    }
    Device --o Actuator : uses (actuators)

    class HWComponent
    Device --o HWComponent : uses (hw)

    class HIDProperty {
        -keys List[str]

        +populate(action) %% Transform a high-level action ()
    }
    Endpoint --o HIDProperty : uses (_hid_properties)


`simulate_action()` Sequence Diagram
####################################

.. mermaid::

    sequenceDiagram

    participant API User
    participant Device
    participant Actuator
    participant Endpoint
    participant HIDProperty

    API User->>Device: simulate_action(action)

    Device->>+Device: hid_action = transform_action(action)
    loop actuators
        Device-->>Actuator: transform(data)
    end
    Device-->>-Device: 

    Device->>+Endpoint: populate_hid_data(hid_action, packets)
    loop HID properties
        Endpoint-->>HIDProperty: populate(hid_action, packets)
    end
    Endpoint-->>-Device: 

    loop packets
        Device->>Endpoint: send(create_report(packet))
    end

    Device-->>API User: 

Here's what is being generated: https://pkgbuild.com/~ffy00/documentation/ratbag-emu-sphix-demo/design.html

Modules not being mocked before calling

I'm trying to use autoclasstree at the top of a document to show the hierarchy. When I run make html I get an error saying

Mermaid error:
Could not import <my module> (exception: No module named 'pandas')

When I move the diagram to the bottom of the page, after calling automodule to generate references, the build completes successfully and the diagram will render. The references I'm generating refer to the same module i'm trying to build the diagram for, so it looks like pandas is getting mocked at some point, just not before the diagram is rendered.

Output shows html code after a search

Hi and thanks for this really handy plugin!

I noticed that when I run a search and when I open a page with a Mermaid diagram that contains a search result (therefore highlighted), the Mermaid elements show the highlight html code:

screen shot 2018-06-13 at 09 02 19

In another project, it also prevents the diagram for being displayed.

Could you check if you can reproduce this issue?

I use the following extensions that I imagine should not have any impact:

'sphinx.ext.ifconfig', 'sphinxcontrib.spelling', 'sphinxcontrib.mermaid', 'sphinx.ext.todo', 'sphinxprettysearchresults', 'retina_images'.

Thank you.

Mermaid script gets loaded a lot of times

Hi,

I noticed that Firefox was spending a lot of time loading UNPKG links whilst opening my docs. Apparently mermaid gets initialized 51 times.

I'm running sphinxcontrib-mermaid 0.7.1 and sphinx-build 4.3.2. Is this happening to more people?

<head>
  <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>...</title>
      <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
      <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <!--[if lt IE 9]>
    <script src="../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
        <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
        <script src="../_static/jquery.js"></script>
        <script src="../_static/underscore.js"></script>
        <script src="../_static/doctools.js"></script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
        <script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
        <script>mermaid.initialize({startOnLoad:true});</script>
    <script src="../_static/js/theme.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="..." href="....html" />
    <link rel="prev" title="..." href="....html" /> 
</head>

Upload source dist to pypi

The source dist of the last version (0.5) of sphinxcontrib-mermaid is not available on pypi and it is necessary to package it on conda-forge - currently at 0.4.

Building documentation as latex does not work with png

I'm trying to build the latex files for my documentation while rendering my mermaid charts as png.

I'm able to render the charts as png when building as html - this works as intended.

However, when rendering as latex, the output is a full PDF page for each mermaid chart, which causes issues in the resulting PDF compilation. I assume this is because the png part is not being registered properly.

I'm using Sphinx 1.8.5 and my conf.py is as below:

mermaid_pdfcrop = True
mermaid_output_format = "png"

Load mermaid.min.js conditionally?

As soon as the sphinxcontrib-mermaid extension is enabled in conf.py, ALL generated html files load mermaid.min.js whether they include a Mermaid directive or not:

<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>

This file is about 1MB in size, not much, but currently the biggest file my site loads. 99% of the time there's no need for it since I don't have that many Mermaid diagrams.

This has been flagged by Lighthouse as an Opportunity and I agree with it :)

I don't think it's too hard to make the load of this javascript conditional to the Mermaid directive being actually used in a page?

Excellent

Hi @mgaitan I wanted to open (and quickly close) a quick issue to let you know that this module is wonderful. What a time saver! We're now embedding roadmaps, sequence diagrams and other bits in all our docs. Truly epic.

Thanks!

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.