Skip to content

Add sphinx_runpython.runmermaid extension for Mermaid diagram support#58

Merged
sdpython merged 8 commits into
mainfrom
copilot/extend-runpython-plot-graph-mermaid
May 4, 2026
Merged

Add sphinx_runpython.runmermaid extension for Mermaid diagram support#58
sdpython merged 8 commits into
mainfrom
copilot/extend-runpython-plot-graph-mermaid

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 4, 2026

Adds a new sphinx_runpython.runmermaid Sphinx extension exposing a .. runmermaid:: directive that renders Mermaid diagrams. The name runmermaid avoids conflicts with the existing sphinxcontrib-mermaid extension (which also registers .. mermaid::) and the mermaid-py Python package. HTML output is rendered client-side via the Mermaid CDN JS library; LaTeX/text/RST outputs fall back to verbatim source.

New extension: sphinx_runpython/runmermaid/

  • RunMermaidDirective.. runmermaid:: directive with:
    • :script: – body is Python code whose stdout is the diagram definition; an optional string value acts as a split token (only output after that token is used)
    • :process: – run the script in a subprocess
    • Result caching: identical scripts are not re-executed within a build
  • Node visitors for HTML (<pre class="mermaid">), RST, text, and LaTeX
  • add_mermaid_jsbuilder-inited hook that injects mermaid.min.js from CDN into HTML pages

Usage

.. runmermaid::

    graph LR
        A --> B --> C

.. runmermaid::
    :script: DIAGRAM

    print("DIAGRAM")
    print("graph LR\n    A --> B")

Supporting changes

  • _doc/conf.py – extension registered as sphinx_runpython.runmermaid, Mermaid added to epkg_dictionary
  • _doc/api/runmermaid.rst + _doc/api/index.rst – documentation page
  • _unittests/ut_runmermaid/test_runmermaid_extension.py – 5 tests covering inline RST/HTML rendering, script execution, split-token filtering, and caching

Copilot AI linked an issue May 4, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Add functionality to extend runpython for graph plotting with mermaid Add sphinx_runpython.mermaid extension for Mermaid diagram support May 4, 2026
Copilot finished work on behalf of xadupre May 4, 2026 09:27
Copilot AI requested a review from xadupre May 4, 2026 09:27
Comment thread sphinx_runpython/mermaid/sphinx_mermaid_extension.py Outdated
Copilot AI changed the title Add sphinx_runpython.mermaid extension for Mermaid diagram support Add sphinx_runpython.mermaidjs extension for Mermaid diagram support May 4, 2026
Copilot AI requested a review from xadupre May 4, 2026 09:34
Copilot finished work on behalf of xadupre May 4, 2026 09:35
Comment thread _doc/api/mermaidjs.rst Outdated
Agent-Logs-Url: https://github.com/sdpython/sphinx-runpython/sessions/d779d538-fb95-4f79-ba03-95dfc33cf6e0

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copilot AI changed the title Add sphinx_runpython.mermaidjs extension for Mermaid diagram support Add sphinx_runpython.runmermaid extension for Mermaid diagram support May 4, 2026
Copilot AI requested a review from xadupre May 4, 2026 09:46
Copilot finished work on behalf of xadupre May 4, 2026 09:46
Comment thread _doc/api/index.rst Outdated
Copilot finished work on behalf of xadupre May 4, 2026 09:52
Copilot AI requested a review from xadupre May 4, 2026 09:52
@xadupre
Copy link
Copy Markdown
Collaborator

xadupre commented May 4, 2026

@copilot merge with main branch

…hon-plot-graph-mermaid

Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 4, 2026

@copilot merge with main branch

Done in 1aa681d. Merged main into the branch (auto-merged _doc/conf.py, removed azure-pipelines.yml, and picked up small updates to README.rst, _doc/index.rst, and ext_test_case.py).

Copilot finished work on behalf of xadupre May 4, 2026 10:17
@xadupre xadupre marked this pull request as ready for review May 4, 2026 11:16
@sdpython sdpython merged commit fd97dcb into main May 4, 2026
16 of 17 checks passed
@sdpython sdpython deleted the copilot/extend-runpython-plot-graph-mermaid branch May 4, 2026 11:17
Copilot AI added a commit that referenced this pull request May 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

extend runpython to plot graph with mermaid

3 participants