diff --git a/roots/test-title-empty-groups/conf.py b/roots/test-title-empty-groups/conf.py new file mode 100644 index 0000000..9f2a54a --- /dev/null +++ b/roots/test-title-empty-groups/conf.py @@ -0,0 +1,8 @@ +from __future__ import annotations + +import sys +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).parent)) +extensions = ["sphinx_argparse_cli"] +nitpicky = True diff --git a/roots/test-title-empty-groups/index.rst b/roots/test-title-empty-groups/index.rst new file mode 100644 index 0000000..170b1af --- /dev/null +++ b/roots/test-title-empty-groups/index.rst @@ -0,0 +1,4 @@ +.. sphinx_argparse_cli:: + :module: parser + :func: make + :title: diff --git a/roots/test-title-empty-groups/parser.py b/roots/test-title-empty-groups/parser.py new file mode 100644 index 0000000..8bbad68 --- /dev/null +++ b/roots/test-title-empty-groups/parser.py @@ -0,0 +1,9 @@ +from __future__ import annotations + +from argparse import ArgumentParser + + +def make() -> ArgumentParser: + parser = ArgumentParser(prog="tool") + parser.add_argument("--verbose", action="store_true", help="be verbose") + return parser diff --git a/src/sphinx_argparse_cli/_logic.py b/src/sphinx_argparse_cli/_logic.py index 1429395..b3d2699 100644 --- a/src/sphinx_argparse_cli/_logic.py +++ b/src/sphinx_argparse_cli/_logic.py @@ -187,7 +187,7 @@ def run(self) -> list[Node]: self.env.note_reread() # this document needs to be always updated title_text = self.options.get("title", f"{self.parser.prog} - CLI interface").strip() if not title_text: - home_section: Element = paragraph() + home_section: Element = section("") else: home_section = section("", title("", Text(title_text)), ids=[self.make_id(title_text)], names=[title_text]) diff --git a/tests/test_logic.py b/tests/test_logic.py index b0f46c9..f02a0ca 100644 --- a/tests/test_logic.py +++ b/tests/test_logic.py @@ -403,3 +403,9 @@ def test_prog_subcommands(build_outcome: str) -> None: def test_multiword_prog(build_outcome: str) -> None: assert "python -m build positional arguments" in build_outcome assert "python -m build options" in build_outcome + + +@pytest.mark.sphinx(buildername="html", testroot="title-empty-groups") +def test_empty_title_groups_in_toctree(build_outcome: str) -> None: + assert '
' in build_outcome + assert "be verbose" in build_outcome