From 6afede282f4b108be0ebcf4473c9ea11a33fb126 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Mon, 9 Sep 2024 22:46:10 -0400 Subject: [PATCH 1/2] Support latest es module mermaid, add support for ELK diagrams --- README.rst | 40 ++++++++-- setup.py | 1 + sphinxcontrib/mermaid.py | 165 +++++++++++++++++++++++++++------------ tests/conftest.py | 2 +- tests/test_html.py | 67 +++++++++++++--- 5 files changed, 204 insertions(+), 71 deletions(-) diff --git a/README.rst b/README.rst index bbba2b5..e4ab738 100644 --- a/README.rst +++ b/README.rst @@ -132,6 +132,10 @@ Directive options A preview after adding ``:zoom:`` option only to the first diagram example above: +``:config:``: JSON to pass through to the `mermaid configuration `_ + +``:title:``: Title to pass through to the `mermaid configuration `_ + Config values ------------- @@ -141,22 +145,40 @@ Config values 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_use_local`` + + Optional path to a local installation of ``mermaid.esm.min.mjs``. By default, we will pull from jsdelivr. + ``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. + 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 ``"11.2.0"``. - 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``:: +``mermaid_init_js`` + Mermaid initialization code. Default to ``"mermaid.initialize({startOnLoad:false});"``. - html_js_files = [ - 'js/mermaid.js', - ] +.. versionchanged:: 0.7 + The init code doesn't include the `' + '' in index ) - assert "" in index + assert '' in index assert ( """
sequenceDiagram @@ -33,6 +34,7 @@ def test_html_raw(index): @pytest.mark.sphinx("html", testroot="basic") def test_html_zoom_option(index, app): + assert "mermaid.run()" in index assert "svg.call(zoom);" not in index zoom_page = (app.outdir / "zoom.html").read_text().replace("' + '' in index ) -@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_version": None}) -def test_conf_mermaid_no_version(app, index): - # requires local mermaid +@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_use_local": "test", "mermaid_include_elk": ""}) +def test_conf_mermaid_local(app, index): + assert "mermaid.run()" in index assert "mermaid.min.js" not in index +@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_use_local": "test", "mermaid_elk_use_local": "test"}) +def test_conf_mermaid_elk_local(app, index): + assert "mermaid.run()" in index + assert "mermaid.min.js" not in index + assert "mermaid-layout-elk.esm.min.mjs" not in index + + +@pytest.mark.sphinx("html", testroot="basic", confoverrides={"d3_version": "1.2.3", "mermaid_include_elk": ""}) +def test_conf_d3_version(app, index): + assert "mermaid.run()" in index + assert app.config.d3_version == "1.2.3" + assert ( + '' + in index + ) + + +@pytest.mark.sphinx("html", testroot="basic", confoverrides={"d3_use_local": "test"}) +def test_conf_d3_local(app, index): + assert "d3" not in index + + @pytest.mark.sphinx( "html", testroot="basic", confoverrides={"mermaid_init_js": "custom script;"} ) def test_mermaid_init_js(index): - assert "" not in index - assert "" in index + assert "mermaid.run()" in index + assert '' not in index + assert '' in index + + +@pytest.mark.sphinx("html", testroot="basic", confoverrides={"mermaid_include_elk": "latest"}) +def test_mermaid_with_elk(app, index): + assert "mermaid.run()" in index + assert ( + '' + in index + ) @pytest.mark.sphinx("html", testroot="markdown") def test_html_raw_from_markdown(index): + assert "mermaid.run()" in index assert ( - '' + '' in index ) - assert "" in index + assert '' in index assert ( """
From d6537f4926806663a7f269485ccdbdc15ba35b21 Mon Sep 17 00:00:00 2001 From: Tim Paine <3105306+timkpaine@users.noreply.github.com> Date: Wed, 11 Sep 2024 21:48:52 -0400 Subject: [PATCH 2/2] Drop deprecated pythons, macos-latest is arm-only with min python 3.8 --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6d3d7cd..91980e9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,14 +11,14 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["pypy3.8", "3.7", "3.8", "3.9", "3.10", "3.11", "3.12-dev"] + python-version: ["pypy3.9", "3.9", "3.10", "3.11", "3.12"] os: [windows-latest, macos-latest, ubuntu-latest] steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: ${{ matrix.python-version }} cache: pip