From 85ccde8fe216f507a96418a0041f2e2b3f2ed9b5 Mon Sep 17 00:00:00 2001 From: Tony Narlock Date: Sun, 5 Jul 2026 09:45:02 -0500 Subject: [PATCH 1/9] mermaid(feat[responsive]): Add diagram policy why: Responsive diagram behavior needs an author-facing contract so Sphinx pages can choose between scaled diagrams and intrinsic-width scrolling without adding client-side Mermaid runtime behavior. what: - Add fit and preserve responsive policies to the mermaid directive - Emit responsive classes and data attributes on rendered figures - Split CSS behavior for scaled and preserved SVG diagrams - Document responsive authoring guidance and cover the markup in tests --- docs/_ext/mermaid_examples.py | 9 +- docs/packages/sphinx-gp-mermaid/how-to.md | 32 ++++++- packages/sphinx-gp-mermaid/README.md | 7 ++ .../src/sphinx_gp_mermaid/__init__.py | 88 +++++++++++++++++-- .../_static/css/sphinx_gp_mermaid.css | 19 ++-- .../__snapshots__/test_integration.ambr | 2 +- tests/ext/mermaid/test_css.py | 32 +++++++ tests/ext/mermaid/test_examples_page.py | 2 +- tests/ext/mermaid/test_integration.py | 21 ++++- tests/ext/mermaid/test_mermaid.py | 72 ++++++++++++++- 10 files changed, 262 insertions(+), 22 deletions(-) create mode 100644 tests/ext/mermaid/test_css.py diff --git a/docs/_ext/mermaid_examples.py b/docs/_ext/mermaid_examples.py index 23bcbe06..255f64c9 100644 --- a/docs/_ext/mermaid_examples.py +++ b/docs/_ext/mermaid_examples.py @@ -56,7 +56,9 @@ def _figure_markup(light: str, dark: str, *, alt: str) -> str: ``body[data-theme]`` rules toggle the committed variants with no script. >>> markup = _figure_markup("", "", alt="A flow") - >>> 'class="gp-sphinx-mermaid"' in markup + >>> 'class="gp-sphinx-mermaid gp-sphinx-mermaid--fit"' in markup + True + >>> 'data-mermaid-responsive="fit"' in markup True >>> markup.count("gp-sphinx-mermaid__variant--theme-") 2 @@ -68,7 +70,10 @@ def _figure_markup(light: str, dark: str, *, alt: str) -> str: aria = f' aria-label="{html.escape(alt, quote=True)}"' return "".join( [ - '
', + ( + '
' + ), ( '