{"id":2776,"library":"sphinxcontrib-mermaid","title":"Sphinxcontrib Mermaid","description":"Sphinxcontrib Mermaid (version 2.0.1) is a Sphinx extension that enables embedding Mermaid.js diagrams directly into reStructuredText or Markdown documentation. It allows authors to create various diagrams like flowcharts, sequence diagrams, class diagrams, and Gantt charts using a simple text-based syntax. This approach ensures diagrams are version-controlled, easy to maintain, and rendered consistently with the Sphinx theme. The library is actively maintained, supports Python >=3.10, and is distributed via PyPI.","status":"active","version":"2.0.1","language":"en","source_language":"en","source_url":"https://github.com/mgaitan/sphinxcontrib-mermaid","tags":["Sphinx","documentation","diagrams","Mermaid","flowcharts","sequence diagrams","developer tools"],"install":[{"cmd":"pip install sphinxcontrib-mermaid","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Core documentation generator, this is a Sphinx extension.","package":"Sphinx"},{"reason":"Required for rendering Mermaid diagrams to image formats (PNG/SVG) and for PDF builds. Must be installed via npm.","package":"mermaid-cli","optional":true},{"reason":"Required for embedding Mermaid diagrams within Markdown files in Sphinx projects.","package":"myst-parser","optional":true}],"imports":[{"note":"Add 'sphinxcontrib.mermaid' to the 'extensions' list in your project's conf.py to enable the directive.","symbol":"sphinxcontrib.mermaid","correct":"extensions = ['sphinxcontrib.mermaid']"}],"quickstart":{"code":"# conf.py\nimport os\nimport sys\nsys.path.insert(0, os.path.abspath('.'))\n\nproject = 'My Sphinx Project'\ncopyright = '2026, Your Name'\nextensions = [\n    'sphinx.ext.autodoc',\n    'sphinx.ext.napoleon',\n    'sphinxcontrib.mermaid',\n]\n\n# Optional: configure mermaid output for non-raw formats (requires mermaid-cli)\n# mermaid_output_format = 'svg' # or 'png'\n# mermaid_cmd = 'npx mmdc' # if mmdc is in node_modules/.bin or globally installed\n\n# Optional: pin mermaid.js version\n# mermaid_version = \"11.12.1\"\n\n# index.rst (or any .rst file)\n# Here's a simple flowchart:\n#\n# .. mermaid::\n#    graph TD\n#        A[Start] --> B{Decision};\n#        B -->|One| C[Process 1];\n#        B -->|Two| D[Process 2];\n#        C --> E[End];\n#        D --> E;\n#\n# And a sequence diagram:\n#\n# .. mermaid::\n#    sequenceDiagram\n#        participant Alice\n#        participant Bob\n#        Alice->>Bob: Hello Bob, how are you?\n#        alt healthy\n#            Bob->>Alice: Great!\n#        else unwell\n#            Bob->>Alice: Not so good :(\n#        end\n#        Alice->>Bob: Ok, bye!","lang":"python","description":"After installing the package, add 'sphinxcontrib.mermaid' to your `extensions` list in `conf.py`. Then, use the `.. mermaid::` directive in your reStructuredText or Markdown files to embed Mermaid code. For image output (SVG/PNG) or PDF builds, `mermaid-cli` must also be installed via npm."},"warnings":[{"fix":"Install `mermaid-cli` globally or locally via npm (`npm install -g @mermaid-js/mermaid-cli`) and optionally configure `mermaid_cmd` in `conf.py` (e.g., `mermaid_cmd = 'npx mmdc'`).","message":"For non-raw HTML output (PNG, SVG) or when building PDFs, `mermaid-cli` (an npm package) must be installed and accessible. Without it, image rendering will fail. The `mermaid_cmd` configuration option may be needed to specify its path.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Add `mermaid_output_format = 'svg'` (or 'png') to your `conf.py`. Remember this also requires `mermaid-cli`.","message":"The default `mermaid_output_format` is 'raw', which renders Mermaid directly in HTML via JavaScript. If you need static images (e.g., for PDF builds or certain HTML themes), you must explicitly set `mermaid_output_format` to 'svg' or 'png' in `conf.py`.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Resolve conflicts by adding `nbsphinx_requirejs_path = ''` or `jupyter_sphinx_require_url = ''` to your `conf.py` as appropriate.","message":"Known `requirejs` conflicts exist when using `sphinxcontrib-mermaid` alongside extensions like `nbsphinx` or `jupyter-sphinx`, leading to JavaScript errors where Mermaid may not load.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Monitor the GitHub repository for updates on maintenance status and consider contributing if possible.","message":"The project is actively seeking new maintainers, which could impact future development and support.","severity":"deprecated","affected_versions":"2.0.1 onwards"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}