@@ -434,21 +434,49 @@ def get_location(self) -> str:
434434 return f'<unknown>:{ line } '
435435 return ''
436436
437- def parse_content_to_nodes (self ) -> list [Node ]:
438- """Parse the directive's content into nodes."""
439- return nested_parse_to_nodes (self .state , self .content , offset = self .content_offset )
440-
441- def parse_text_to_nodes (self , text : str = '' , / , * , offset : int = - 1 ) -> list [Node ]:
437+ def parse_content_to_nodes (self , allow_section_headings : bool = False ) -> list [Node ]:
438+ """Parse the directive's content into nodes.
439+
440+ :param allow_section_headings:
441+ Are titles (sections) allowed in the directive's content?
442+ Note that this option bypasses Docutils' usual checks on
443+ doctree structure, and misuse of this option can lead to
444+ an incoherent doctree. In Docutils, section nodes should
445+ only be children of ``Structural`` nodes, which includes
446+ ``document``, ``section``, and ``sidebar`` nodes.
447+ """
448+ return nested_parse_to_nodes (
449+ self .state ,
450+ self .content ,
451+ offset = self .content_offset ,
452+ allow_section_headings = allow_section_headings ,
453+ )
454+
455+ def parse_text_to_nodes (
456+ self , text : str = '' , / , * , offset : int = - 1 , allow_section_headings : bool = False ,
457+ ) -> list [Node ]:
442458 """Parse *text* into nodes.
443459
444460 :param text:
445461 Text, in string form. ``StringList`` is also accepted.
462+ :param allow_section_headings:
463+ Are titles (sections) allowed in *text*?
464+ Note that this option bypasses Docutils' usual checks on
465+ doctree structure, and misuse of this option can lead to
466+ an incoherent doctree. In Docutils, section nodes should
467+ only be children of ``Structural`` nodes, which includes
468+ ``document``, ``section``, and ``sidebar`` nodes.
446469 :param offset:
447470 The offset of the content.
448471 """
449472 if offset == - 1 :
450473 offset = self .content_offset
451- return nested_parse_to_nodes (self .state , text , offset = offset )
474+ return nested_parse_to_nodes (
475+ self .state ,
476+ text ,
477+ offset = offset ,
478+ allow_section_headings = allow_section_headings ,
479+ )
452480
453481 def parse_inline (
454482 self , text : str , * , lineno : int = - 1 ,
0 commit comments