Skip to content

Commit b1cb2af

Browse files
Apply multiline handling to group description (#152)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent b919ed6 commit b1cb2af

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

roots/test-description-multiline/parser.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
def make() -> ArgumentParser:
7-
return ArgumentParser(
7+
parser = ArgumentParser(
88
prog="foo",
99
description="""This description
1010
spans multiple lines.
@@ -17,3 +17,11 @@ def make() -> ArgumentParser:
1717
formatter_class=RawDescriptionHelpFormatter,
1818
add_help=False,
1919
)
20+
group = parser.add_argument_group(
21+
description="""This group description
22+
23+
spans multiple lines.
24+
"""
25+
)
26+
group.add_argument("--dummy")
27+
return parser

src/sphinx_argparse_cli/_logic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ def _mk_option_group(self, group: _ArgumentGroup, prefix: str) -> section:
194194
# the text sadly needs to be prefixed, because otherwise the autosectionlabel will conflict
195195
header = title("", Text(title_text))
196196
group_section = section("", header, ids=[ref_id], names=[ref_id])
197-
if group.description:
198-
group_section += paragraph("", Text(group.description))
197+
if description := self._pre_format(group.description):
198+
group_section += description
199199
self._register_ref(ref_id, title_text, group_section)
200200
opt_group = bullet_list()
201201
for action in group._group_actions: # noqa: SLF001

tests/test_logic.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ def test_multiline_description_as_html(build_outcome: str) -> None:
107107
)
108108
assert ref in build_outcome
109109

110+
ref = "This group description\n\nspans multiple lines.\n"
111+
assert ref in build_outcome
112+
110113

111114
@pytest.mark.sphinx(buildername="text", testroot="epilog-set")
112115
def test_set_epilog_as_text(build_outcome: str) -> None:

0 commit comments

Comments
 (0)