diff --git a/docs/src/components.md b/docs/src/components.md index 131d3cc..66fb526 100644 --- a/docs/src/components.md +++ b/docs/src/components.md @@ -8,9 +8,10 @@ This page renders theme-native directives and commonly used Sphinx content with ### Steps -The `steps` directive turns its child headings into a numbered walkthrough. +The `fuma-steps` directive turns its child headings into a numbered walkthrough. +If your project uses Sphinx Design 0.8 or later, rename existing heading-based `steps` blocks to `fuma-steps`. Fuma still accepts `steps` when no other extension registers that name. -::::\{steps} +```{fuma-steps} ### Install the package @@ -23,10 +24,10 @@ Set `html_theme = "fuma"` in `conf.py`. ### Build the site Run the normal Sphinx HTML builder. -:::: +``` ````markdown -```{steps} +```{fuma-steps} ### Install the package Add sphinx-fuma to the documentation environment. diff --git a/sphinx_fuma/_steps.py b/sphinx_fuma/_steps.py index 87415b9..fa80ea8 100644 --- a/sphinx_fuma/_steps.py +++ b/sphinx_fuma/_steps.py @@ -1,12 +1,12 @@ -"""The ``steps`` directive. +"""The ``fuma-steps`` directive. -fumadocs renders numbered walkthroughs as a rail of circled step numbers. There -is no Sphinx equivalent, so a thin container directive marks the region and the -stylesheet draws the rail from the headings inside it. +The stylesheet draws a rail of circled step numbers from the headings inside +the container. """ from docutils import nodes from docutils.parsers.rst import Directive +from sphinx.util.docutils import is_directive_registered __all__ = ("setup_steps",) @@ -24,5 +24,12 @@ def run(self): return [container] +def _register_steps_alias(app) -> None: + if not is_directive_registered("steps"): + app.add_directive("steps", StepsDirective) + + def setup_steps(app) -> None: - app.add_directive("steps", StepsDirective) + app.add_directive("fuma-steps", StepsDirective) + # Wait for all extensions and the HTML theme to register their directives. + app.connect("builder-inited", _register_steps_alias) diff --git a/sphinx_fuma/tests/test_theme.py b/sphinx_fuma/tests/test_theme.py index 36c41f0..3c9857c 100644 --- a/sphinx_fuma/tests/test_theme.py +++ b/sphinx_fuma/tests/test_theme.py @@ -1,4 +1,6 @@ import re +import subprocess +import sys from pathlib import Path import pytest @@ -353,6 +355,51 @@ def test_step_bodies_are_preserved(self, built): steps = html.split('class="fd-steps', 1)[1].split("", 1)[0] assert "Pull it down" in steps + @pytest.mark.parametrize( + "extensions", + [ + ["sphinx_design", "sphinx_fuma"], + ["sphinx_fuma", "sphinx_design"], + ["sphinx_design"], + ], + ) + def test_fuma_steps_and_sphinx_design_steps_render_together(self, tmp_path, extensions): + pytest.importorskip("sphinx_design.steps") + (tmp_path / "conf.py").write_text(f"extensions = {extensions!r}\nhtml_theme = 'fuma'\n") + (tmp_path / "index.rst").write_text( + """Steps +===== + +.. fuma-steps:: + + .. rubric:: Install Fuma + + Install the theme. + +.. steps:: + :start: 3 + + .. step:: Install Sphinx Design + + Install the extension. +""" + ) + out = tmp_path / "_build" + result = subprocess.run( + [sys.executable, "-m", "sphinx", "-W", "-b", "html", str(tmp_path), str(out)], + check=False, + capture_output=True, + text=True, + ) + assert result.returncode == 0, result.stderr + html = (out / "index.html").read_text() + assert 'class="fd-steps' in html + design_steps = re.search(r"]*\bsd-steps\b[^>]*>", html) + assert design_steps is not None + assert 'start="3"' in design_steps[0] + assert "Install the theme." in html + assert "Install the extension." in html + class TestFiles: def test_directive_builds_a_tree(self, built):