File tree Expand file tree Collapse file tree 6 files changed +53
-1
lines changed Expand file tree Collapse file tree 6 files changed +53
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
All notable changes to this project will be documented in this file.
4
4
5
+ ## Unreleased
6
+
7
+ - Allow to add content to directive.
8
+
5
9
## 1.13.1
6
10
7
11
- Fix multiline handling of group descriptions.
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_1
4
+
5
+ Some text inside first directive.
6
+
7
+ .. sphinx_argparse_cli ::
8
+ :module: parser
9
+ :func: make_2
10
+
11
+ Some text inside second directive.
12
+
13
+ Some text after directives.
Original file line number Diff line number Diff line change
1
+ from __future__ import annotations
2
+
3
+ from argparse import ArgumentParser
4
+
5
+
6
+ def make_1 () -> ArgumentParser :
7
+ return ArgumentParser (prog = "basic-1" )
8
+
9
+
10
+ def make_2 () -> ArgumentParser :
11
+ return ArgumentParser (prog = "basic-2" )
Original file line number Diff line number Diff line change @@ -57,7 +57,7 @@ def make_id(key: str) -> str:
57
57
58
58
class SphinxArgparseCli (SphinxDirective ):
59
59
name = "sphinx_argparse_cli"
60
- has_content = False
60
+ has_content = True
61
61
option_spec : ClassVar [dict [str , Any ]] = {
62
62
"module" : unchanged_required ,
63
63
"func" : unchanged_required ,
@@ -173,6 +173,9 @@ def run(self) -> list[Node]:
173
173
if epilog := self ._pre_format (self .options .get ("epilog" , self .parser .epilog )):
174
174
home_section += epilog
175
175
176
+ if self .content :
177
+ self .state .nested_parse (self .content , self .content_offset , home_section )
178
+
176
179
return [home_section ]
177
180
178
181
def _pre_format (self , block : None | str ) -> None | paragraph | literal_block :
Original file line number Diff line number Diff line change @@ -297,3 +297,16 @@ def test_with_default(build_outcome: str) -> None:
297
297
* **"x"** - arg (default: True)
298
298
"""
299
299
)
300
+
301
+
302
+ @pytest .mark .sphinx (buildername = "html" , testroot = "nested" )
303
+ def test_nested_content (build_outcome : str ) -> None :
304
+ assert '<section id="basic-1---CLI-interface">' in build_outcome
305
+ assert "<h1>basic-1 - CLI interface" in build_outcome
306
+ assert "<h2>basic-1 opt" in build_outcome
307
+ assert "<p>Some text inside first directive.</p>" in build_outcome
308
+ assert '<section id="basic-2---CLI-interface">' in build_outcome
309
+ assert "<h2>basic-2 - CLI interface" in build_outcome
310
+ assert "<h3>basic-2 opt" in build_outcome
311
+ assert "<p>Some text inside second directive.</p>" in build_outcome
312
+ assert "<p>Some text after directives.</p>" in build_outcome
You can’t perform that action at this time.
0 commit comments