• Stars
    star
    281
  • Rank 147,023 (Top 3 %)
  • Language
    Python
  • License
    Other
  • Created over 8 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Mermaid diagrams in yours sphinx powered docs
https://img.shields.io/pypi/v/sphinxcontrib-mermaid https://img.shields.io/pypi/dm/shbin

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.

.. 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!


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:
.. autoclasstree:: sphinx.util.DownloadFiles sphinx.util.ExtensionError
   :full:


Or directly the module:

.. autoclasstree:: sphinx.util
.. autoclasstree:: 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.

https://user-images.githubusercontent.com/16781833/228022911-c26d1e01-7f71-4ab7-bb33-ce53056f8343.gif

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});".
.. versionchanged:: 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
  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']
    

More Repositories

1

waliki

A wiki engine powered by Django and Git
Python
309
star
2

sublime-rst-completion

Restructured Text snippets and code completion hotkeys for Sublime Text 2 and 3
Python
248
star
3

curso-python-cientifico

Curso de Python orientado a estudiantes de ciencias e ingeniería, profesores, investigadores e ingenieros
Jupyter Notebook
158
star
4

fortran_magic

An extension for IPython/Jupyter that helps to use Fortran in your interactive session.
Python
115
star
5

preciosa

Inteligencia colectiva contra la inflación
Python
67
star
6

departamentos_argentina

Geojson/Topojson de Argentina a nivel departamentos
40
star
7

pytest-line-profiler

Profile code executed by pytest, line by line.
Python
24
star
8

django-orm-magic

An extension for IPython that help to define and use django's models on the fly
Jupyter Notebook
23
star
9

radiocut_downloader

Download contents from radiocut.fm
Python
20
star
10

pymips

A pipelined MIPS processor implemented in Python
Python
19
star
11

miau

Remix speeches for fun and profit
Python
17
star
12

waliki_flask

A simple yet powerful wiki engine -- Deprecated. New version:
JavaScript
17
star
13

moin2git

Migrate a MoinMoin wiki as a Git repository
Python
15
star
14

tisu

your project's issue tracker, in a text file
Python
8
star
15

preciosa_mobile

Aplicación cliente para smartphones del proyecto Preciosa
JavaScript
7
star
16

sqlalchemy-pretty-sql

Given a sqlalchemy query, display its well formatted and highlighted sql code.
Jupyter Notebook
7
star
17

elecciones_argentina_2013

Dump de datos en formato CSV del programa http://www.resultados.gob.ar/inimesas.htm
6
star
18

discursos_cfk

Discursos de Cristina Fernández de Kirchner
Python
4
star
19

mgaitan.github.io

>>> self.geek.post() (Mi weblog técnico)
HTML
4
star
20

one

one, the missing Python function
Python
4
star
21

forn

contratapas de Juan Forn en Página/12
HTML
4
star
22

f2f_online

Online Fortran 77 to Fortran 90/95 conversor
JavaScript
4
star
23

pytest-leak-finder

Find the test that's leaking before the one that fails
Python
3
star
24

trestapas

A platform to analyze historical newspaper discourses
Python
3
star
25

myhdl-talk

Slides and notes for a MyHDL talk on Cordoba PyDay 2011, Argentina
JavaScript
3
star
26

pytest-portion

Select a portion of the collected tests
Python
3
star
27

h2dp

Hamster to dotProject logs sync tool
Python
3
star
28

pasaron-cosas

https://mgaitan.github.io/pasaron-cosas/slides.html
HTML
3
star
29

git-hooks

scripts to be used as git hooks
Python
2
star
30

clarin_lta

Ignorar la ventana de login obligatoria de clarin.com o lavoz.com.ar
HTML
2
star
31

precios_maximos

Listados de Precios Maximos de Referencia por provincia
Python
2
star
32

gh-weekly

GitHub CLI extension that generates a weekly report in markdown listing the PRs worked on
Shell
2
star
33

hamster2jira

Post your Hamster logs into Jira
Python
2
star
34

intro-git

Introducción a Git - Charla 8va Jornadas de Software Libre de la UNNOBA
JavaScript
2
star
35

my-nikola-theme

The theme for mgaitan.github.io
JavaScript
2
star
36

gpec2010

Python
2
star
37

haztelibro

give a file with a list of urls, get a readable epub
Python
1
star
38

mezzanine-pagedown

Fork from https://bitbucket.org/akhayyat/mezzanine-pagedown
JavaScript
1
star
39

hay-camisetas-bot

¿Hay camisetas ⭐⭐⭐?
Python
1
star
40

en-pija

Generador online de "En pija approved"
1
star
41

video2ebook

A software based book scanner from videos
1
star
42

battleship

Generador de tableros de batalla naval
JavaScript
1
star
43

awesome-scipy

A curated list of python resources for science
1
star
44

django-milligram

Django base template powered by Milligram
HTML
1
star
45

nikolahub

Your Nikola blog rendered in the cloud
Python
1
star
46

datasets_preciosclaros

Datasets resultantes del scraper de preciosclaros.gob.ar
Jupyter Notebook
1
star
47

10consejos

10 consejos para un mejor software (de) científico(s)
JavaScript
1
star
48

esquedulin

Automatically exported from code.google.com/p/esquedulin
Python
1
star
49

presentacion_proyecto_final_gpec

Encontré las diapositivas de presentación de mi proyecto final
HTML
1
star
50

escuelas_argentinas

datasets (y scraper) de establecimientos educativos
Python
1
star
51

elecciones_argentina_2015

dump en CSV y sqlite3 de los resultados del escrutinio provisorio de las presidenciales 2015
1
star
52

wikibora

Una plataforma para el anotado colaborativo de Boletines Oficiales
1
star
53

charla_py3

Python 3 para escépticos
Jupyter Notebook
1
star
54

healthyurl

A simple command-line tool to perform health checks on a given URL using Python's standard library
Python
1
star