File tree Expand file tree Collapse file tree
roots/test-description-multiline Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 1+ .. sphinx_argparse_cli ::
2+ :module: parser
3+ :func: make
Original file line number Diff line number Diff line change 1+ from __future__ import annotations
2+
3+ from argparse import ArgumentParser , RawDescriptionHelpFormatter
4+
5+
6+ def make () -> ArgumentParser :
7+ return ArgumentParser (
8+ prog = "foo" ,
9+ description = """This description
10+ spans multiple lines.
11+
12+ this line is indented.
13+ and also this.
14+
15+ Now this should be a separate paragraph.
16+ """ ,
17+ formatter_class = RawDescriptionHelpFormatter ,
18+ add_help = False ,
19+ )
Original file line number Diff line number Diff line change 77 Action ,
88 ArgumentParser ,
99 HelpFormatter ,
10+ RawDescriptionHelpFormatter ,
1011 _ArgumentGroup ,
1112 _StoreFalseAction ,
1213 _StoreTrueAction ,
@@ -148,8 +149,12 @@ def run(self) -> list[Node]:
148149
149150 description = self .options .get ("description" , self .parser .description )
150151 if description :
151- desc_paragraph = paragraph ("" , Text (description ))
152- home_section += desc_paragraph
152+ if isinstance (self .parser .formatter_class ("" ), RawDescriptionHelpFormatter ) and "\n " in description :
153+ lit = literal_block ("" , Text (description ))
154+ lit ["language" ] = "none"
155+ home_section += lit
156+ else :
157+ home_section += paragraph ("" , Text (description ))
153158 # construct groups excluding sub-parsers
154159 home_section += self ._mk_usage (self .parser )
155160 for group in self .parser ._action_groups : # noqa: SLF001
Original file line number Diff line number Diff line change @@ -99,6 +99,15 @@ def test_empty_description_as_text(build_outcome: str) -> None:
9999 assert build_outcome == "foo - CLI interface\n *******************\n \n foo\n "
100100
101101
102+ @pytest .mark .sphinx (buildername = "html" , testroot = "description-multiline" )
103+ def test_multiline_description_as_html (build_outcome : str ) -> None :
104+ ref = (
105+ "This description\n spans multiple lines.\n \n this line is indented.\n and also this.\n \n Now this should be"
106+ " a separate paragraph.\n "
107+ )
108+ assert ref in build_outcome
109+
110+
102111@pytest .mark .sphinx (buildername = "text" , testroot = "complex" )
103112@pytest .mark .prepare (directive_args = [":usage_width: 100" ])
104113def test_usage_width_default (build_outcome : str ) -> None :
You can’t perform that action at this time.
0 commit comments