
    -Ph3                        d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
 erddlmZ ddlmZ dd	lmZ d
ddddd!dZej        d"d            Zd#d ZdS )$z,Docutils utility functions for parsing text.    )annotationsN)TYPE_CHECKING)Element)
StringListstring2lines)Iterator)Node)RSTStatez<generated text>TF)sourceoffsetallow_section_headingskeep_title_contextstater
   textstr | StringListr   strr   intr   boolr   return
list[Node]c               8   | j         }t          |||j        j                  }t	                      }||_         |r|                     ||||           n@t          |           5  |                     ||||           ddd           n# 1 swxY w Y   |j        S )a  Parse *text* into nodes.

    :param state:
        The state machine state. Must be a subclass of ``RSTState``.
    :param text:
        Text, in string form. ``StringList`` is also accepted.
    :param source:
        The text's source, used when creating a new ``StringList``.
    :param offset:
        The offset of the content.
    :param allow_section_headings:
        Are titles (sections) allowed in *text*?
        Note that this option bypasses Docutils' usual checks on
        doctree structure, and misuse of this option can lead to
        an incoherent doctree. In Docutils, section nodes should
        only be children of ``Structural`` nodes, which includes
        ``document``, ``section``, and ``sidebar`` nodes.
    :param keep_title_context:
        If this is False (the default), then *content* is parsed as if it were
        an independent document, meaning that title decorations (e.g. underlines)
        do not need to match the surrounding document.
        This is useful when the parsed content comes from
        a completely different context, such as docstrings.
        If this is True, then title underlines must match those in
        the surrounding document, otherwise the behaviour is undefined.

    .. versionadded:: 7.4
    )r   	tab_width)match_titlesN)document_text_to_string_listsettingsr   r   nested_parse_fresh_title_style_contextchildren)	r   r   r   r   r   r   r   contentnodes	            S/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/sphinx/util/parsing.pynested_parse_to_nodesr#      s    J ~H"Vx'8'B  G 99DDM 7FD?UVVVV'.. 	 	4J    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 =s   $B

BBIterator[None]c              #     K   | j         }|j        }|j        }g |_        d|_        	 d V  ||_        ||_        d S # ||_        ||_        w xY w)Nr   )memotitle_stylessection_level)r   r&   surrounding_title_stylessurrounding_section_levels       r"   r   r   H   sv       :D<@<M%)%7DD7 56 566666s	   ; Ar   r   c              v    t          | t                    r| S t          | |d          }t          ||          S )NT)convert_whitespace)r   )
isinstancer   r   )r   r   r   r    s       r"   r   r   Y   sB     $
## 4tDDDGgf----    )r   r
   r   r   r   r   r   r   r   r   r   r   r   r   )r   r
   r   r$   )r   r   r   r   r   r   r   r   )__doc__
__future__r   
contextlibtypingr   docutils.nodesr   docutils.statemachiner   r   collections.abcr   r	   docutils.parsers.rst.statesr
   r#   contextmanagerr   r    r.   r"   <module>r9      s   2 2 " " " " " "                 " " " " " " : : : : : : : : 5((((((######444444 %#'$3 3 3 3 3 3l 7 7 7 7 . . . . . .r.   