Skip to content

Commit 2e8609c

Browse files
authored
🐛 fix(toctree): use section node when title is empty (#291)
1 parent 7bc2756 commit 2e8609c

5 files changed

Lines changed: 28 additions & 1 deletion

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from pathlib import Path
5+
6+
sys.path.insert(0, str(Path(__file__).parent))
7+
extensions = ["sphinx_argparse_cli"]
8+
nitpicky = True
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.. sphinx_argparse_cli::
2+
:module: parser
3+
:func: make
4+
:title:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from __future__ import annotations
2+
3+
from argparse import ArgumentParser
4+
5+
6+
def make() -> ArgumentParser:
7+
parser = ArgumentParser(prog="tool")
8+
parser.add_argument("--verbose", action="store_true", help="be verbose")
9+
return parser

src/sphinx_argparse_cli/_logic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def run(self) -> list[Node]:
187187
self.env.note_reread() # this document needs to be always updated
188188
title_text = self.options.get("title", f"{self.parser.prog} - CLI interface").strip()
189189
if not title_text:
190-
home_section: Element = paragraph()
190+
home_section: Element = section("")
191191
else:
192192
home_section = section("", title("", Text(title_text)), ids=[self.make_id(title_text)], names=[title_text])
193193

tests/test_logic.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,3 +403,9 @@ def test_prog_subcommands(build_outcome: str) -> None:
403403
def test_multiword_prog(build_outcome: str) -> None:
404404
assert "python -m build positional arguments" in build_outcome
405405
assert "python -m build options" in build_outcome
406+
407+
408+
@pytest.mark.sphinx(buildername="html", testroot="title-empty-groups")
409+
def test_empty_title_groups_in_toctree(build_outcome: str) -> None:
410+
assert '<section id="tool-options">' in build_outcome
411+
assert "be verbose" in build_outcome

0 commit comments

Comments
 (0)