File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33All notable changes to this project will be documented in this file.
44
5+ ## Unreleased
6+
7+ - Allow to add content to directive.
8+
59## 1.13.1
610
711- 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:
5757
5858class SphinxArgparseCli (SphinxDirective ):
5959 name = "sphinx_argparse_cli"
60- has_content = False
60+ has_content = True
6161 option_spec : ClassVar [dict [str , Any ]] = {
6262 "module" : unchanged_required ,
6363 "func" : unchanged_required ,
@@ -173,6 +173,9 @@ def run(self) -> list[Node]:
173173 if epilog := self ._pre_format (self .options .get ("epilog" , self .parser .epilog )):
174174 home_section += epilog
175175
176+ if self .content :
177+ self .state .nested_parse (self .content , self .content_offset , home_section )
178+
176179 return [home_section ]
177180
178181 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:
297297* **"x"** - arg (default: True)
298298"""
299299 )
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