Skip to content

Commit ba85a88

Browse files
committed
Support content in py:module and js:module
1 parent 6f64b9b commit ba85a88

File tree

4 files changed

+28
-7
lines changed

4 files changed

+28
-7
lines changed

sphinx/domains/javascript.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class JSModule(SphinxDirective):
249249
:param mod_name: Module name
250250
"""
251251

252-
has_content = False
252+
has_content = True
253253
required_arguments = 1
254254
optional_arguments = 0
255255
final_argument_whitespace = False
@@ -258,10 +258,14 @@ class JSModule(SphinxDirective):
258258
}
259259

260260
def run(self) -> List[Node]:
261+
content_node = nodes.Element()
262+
self.state.nested_parse(self.content, self.content_offset, content_node,
263+
match_titles=True)
264+
261265
mod_name = self.arguments[0].strip()
262266
self.env.ref_context['js:module'] = mod_name
263267
noindex = 'noindex' in self.options
264-
ret: List[Node] = []
268+
ret: List[Node] = [*content_node.children]
265269
if not noindex:
266270
domain = cast(JavaScriptDomain, self.env.get_domain('js'))
267271

sphinx/domains/python.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@
2828
from sphinx.roles import XRefRole
2929
from sphinx.util import logging
3030
from sphinx.util.docfields import Field, GroupedField, TypedField
31-
from sphinx.util.docutils import SphinxDirective
31+
from sphinx.util.docutils import SphinxDirective, switch_source_input
3232
from sphinx.util.inspect import signature_from_str
33-
from sphinx.util.nodes import find_pending_xref_condition, make_id, make_refnode
33+
from sphinx.util.nodes import (find_pending_xref_condition, make_id, make_refnode,
34+
nested_parse_with_titles)
3435
from sphinx.util.typing import OptionSpec, TextlikeNode
3536

3637
logger = logging.getLogger(__name__)
@@ -967,7 +968,7 @@ class PyModule(SphinxDirective):
967968
Directive to mark description of a new module.
968969
"""
969970

970-
has_content = False
971+
has_content = True
971972
required_arguments = 1
972973
optional_arguments = 0
973974
final_argument_whitespace = False
@@ -984,7 +985,14 @@ def run(self) -> List[Node]:
984985
modname = self.arguments[0].strip()
985986
noindex = 'noindex' in self.options
986987
self.env.ref_context['py:module'] = modname
987-
ret: List[Node] = []
988+
989+
content_node: Element = nodes.section()
990+
with switch_source_input(self.state, self.content):
991+
# necessary so that the child nodes get the right source/line set
992+
content_node.document = self.state.document
993+
nested_parse_with_titles(self.state, self.content, content_node)
994+
995+
ret: List[Node] = [*content_node.children]
988996
if not noindex:
989997
# note module to the domain
990998
node_id = make_id(self.env, self.state.document, 'module', modname)

sphinx/ext/autodoc/__init__.py

+9
Original file line numberDiff line numberDiff line change
@@ -978,6 +978,15 @@ def __init__(self, *args: Any) -> None:
978978
merge_members_option(self.options)
979979
self.__all__: Optional[Sequence[str]] = None
980980

981+
def add_content(self, more_content: Optional[StringList]) -> None:
982+
old_indent = self.indent
983+
self.indent += ' '
984+
super().add_content(None)
985+
self.indent = old_indent
986+
if more_content:
987+
for line, src in zip(more_content.data, more_content.items):
988+
self.add_line(line, src[0], src[1])
989+
981990
@classmethod
982991
def can_document_member(cls, member: Any, membername: str, isattr: bool, parent: Any
983992
) -> bool:

tests/test_ext_autodoc_automodule.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_empty_all(app):
1919
'',
2020
'.. py:module:: target.empty_all',
2121
'',
22-
'docsting of empty_all module.',
22+
' docsting of empty_all module.',
2323
'',
2424
]
2525

0 commit comments

Comments
 (0)