Skip to content

Commit 9533451

Browse files
authored
🐛 fix(toctree): crash with empty title in toctree (#296)
1 parent 144795e commit 9533451

4 files changed

Lines changed: 26 additions & 8 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
CLI
2+
===
3+
4+
.. sphinx_argparse_cli::
5+
:module: parser
6+
:func: make
7+
:title:
Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
.. sphinx_argparse_cli::
2-
:module: parser
3-
:func: make
4-
:title:
1+
Overview
2+
========
3+
4+
.. toctree::
5+
:hidden:
6+
7+
self
8+
cli
9+
10+
See :doc:`cli` for details.

src/sphinx_argparse_cli/_logic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
Node,
2626
Text,
2727
bullet_list,
28+
container,
2829
fully_normalize_name,
2930
list_item,
3031
literal,
@@ -187,7 +188,7 @@ def run(self) -> list[Node]:
187188
self.env.note_reread() # this document needs to be always updated
188189
title_text = self.options.get("title", f"{self.parser.prog} - CLI interface").strip()
189190
if not title_text:
190-
home_section: Element = section("")
191+
home_section: Element = container("")
191192
else:
192193
home_section = section("", title("", Text(title_text)), ids=[self.make_id(title_text)], names=[title_text])
193194

tests/test_logic.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,10 @@ def test_multiword_prog(build_outcome: str) -> None:
407407

408408

409409
@pytest.mark.sphinx(buildername="html", testroot="title-empty-groups")
410-
def test_empty_title_groups_in_toctree(build_outcome: str) -> None:
411-
assert '<section id="tool-options">' in build_outcome
412-
assert "be verbose" in build_outcome
410+
def test_empty_title_groups_in_toctree(app: SphinxTestApp, monkeypatch: pytest.MonkeyPatch) -> None:
411+
monkeypatch.setenv("FORCE_COLOR", "1")
412+
monkeypatch.delenv("NO_COLOR", raising=False)
413+
app.build()
414+
cli_html = (Path(app.outdir) / "cli.html").read_text()
415+
assert '<section id="tool-options">' in cli_html
416+
assert "be verbose" in cli_html

0 commit comments

Comments
 (0)