File tree Expand file tree Collapse file tree 5 files changed +46
-2
lines changed
roots/test-description-multiline Expand file tree Collapse file tree 5 files changed +46
-2
lines changed 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 7
7
Action ,
8
8
ArgumentParser ,
9
9
HelpFormatter ,
10
+ RawDescriptionHelpFormatter ,
10
11
_ArgumentGroup ,
11
12
_StoreFalseAction ,
12
13
_StoreTrueAction ,
@@ -148,8 +149,12 @@ def run(self) -> list[Node]:
148
149
149
150
description = self .options .get ("description" , self .parser .description )
150
151
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 ))
153
158
# construct groups excluding sub-parsers
154
159
home_section += self ._mk_usage (self .parser )
155
160
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:
99
99
assert build_outcome == "foo - CLI interface\n *******************\n \n foo\n "
100
100
101
101
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
+
102
111
@pytest .mark .sphinx (buildername = "text" , testroot = "complex" )
103
112
@pytest .mark .prepare (directive_args = [":usage_width: 100" ])
104
113
def test_usage_width_default (build_outcome : str ) -> None :
You can’t perform that action at this time.
0 commit comments