
    ehg+                        d Z ddlmZ ddlmZmZ ddlZddlmZm	Z	m
Z
mZ ddlmZ  G d d	e	          Z e
d
d          Z G d d          ZdS )zyA tree representation of a linear markdown-it token stream.

This module is not part of upstream JavaScript markdown-it.
    )annotations)	GeneratorSequenceN)Any
NamedTupleTypeVaroverload   )Tokenc                  $    e Zd ZU ded<   ded<   dS )_NesterTokensr   openingclosingN)__name__
__module____qualname____annotations__     `/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/markdown_it/tree.pyr   r      s"         NNNNNNNNr   r   	_NodeTypeSyntaxTreeNode)boundc                     e Zd ZdZ	 dIdddJdZdKdZedLd            ZedMd            ZdNdZdOdZe	dPd            Z
e
j        dQd            Z
e	dRd            Zej        dSd             Ze	dTd!            Ze	dTd"            Ze	dUd$            Ze	dKd%            Ze	dRd&            Ze	dRd'            ZdVd(ZdVd)Zd*d+d,d-dWd1Zdd2dXd5ZdYd7Ze	dKd8            Ze	dZd:            Zd[d=Ze	d\d?            Ze	d]d@            Ze	dKdA            Ze	dKdB            Ze	dKdC            Ze	d^dE            Z e	dTdF            Z!e	dTdG            Z"dHS )_r   ae  A Markdown syntax tree node.

    A class that can be used to construct a tree representation of a linear
    `markdown-it-py` token stream.

    Each node in the tree represents either:
      - root of the Markdown document
      - a single unnested `Token`
      - a `Token` "_open" and "_close" token pair, and the tokens nested in
          between
    r   Tcreate_roottokensSequence[Token]r   boolreturnNonec                  d| _         d| _        d| _        g | _        |r|                     |           dS |st          d          t          |          dk    rJ|d         }|j        rt          d          || _         |j        r|                     |j                   dS dS t          |d         |d                   | _        |                     |dd                    dS )zInitialize a `SyntaxTreeNode` from a token stream.

        If `create_root` is True, create a root node for the document.
        NzGCan only create root from empty token sequence. Set `create_root=True`.r
   r   z;Unequal nesting level at the start and end of token stream.)
tokennester_tokens_parent	_children_set_children_from_tokens
ValueErrorlennestingchildrenr   )selfr   r   inline_tokens       r   __init__zSyntaxTreeNode.__init__$   s    $(
 48 ! %' 	**6222F 	9+   [[A!!9L#  Q   &DJ$ F..|/DEEEEEF F "/vay&*!E!ED**6!B$<88888r   strc                @    t          |           j         d| j          dS )N())typer   r-   s    r   __repr__zSyntaxTreeNode.__repr__N   s$    t**%44	4444r   r-   r   itemintc                    d S Nr   r-   r7   s     r   __getitem__zSyntaxTreeNode.__getitem__Q   s    >Acr   slicelist[_NodeType]c                    d S r:   r   r;   s     r   r<   zSyntaxTreeNode.__getitem__T   s    FIcr   int | slice_NodeType | list[_NodeType]c                    | j         |         S r:   )r,   r;   s     r   r<   zSyntaxTreeNode.__getitem__W   s    }T""r   list[Token]c                0    dfdg } | |           |S )	z Recover the linear token stream.noder   
token_listrC   r    r!   c                N   | j         dk    r| j        D ]} ||           d S | j        r|                    | j                   d S | j        sJ |                    | j        j                   | j        D ]} ||           |                    | j        j                   d S )Nroot)r4   r,   r$   appendr%   r   r   )rE   rF   childrecursive_collect_tokenss      r   rK   z:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokens]   s    yF""!] @ @E,,UJ????@ @ >!!$*-----))))!!$"4"<===!] @ @E,,UJ????!!$"4"<=====r   )rE   r   rF   rC   r    r!   r   )r-   r   rK   s     @r   	to_tokenszSyntaxTreeNode.to_tokensZ   s@    	> 	> 	> 	> 	> 	> !  v...r   c                    | j         S r:   r'   r5   s    r   r,   zSyntaxTreeNode.childrenn   s
    ~r   valuec                    || _         d S r:   rN   r-   rO   s     r   r,   zSyntaxTreeNode.childrenr   s    r   _NodeType | Nonec                    | j         S r:   r&   r5   s    r   parentzSyntaxTreeNode.parentv   s
    |r   c                    || _         d S r:   rT   rQ   s     r   rU   zSyntaxTreeNode.parentz   s    r   c                     | j         p| j         S )z Is the node a special root node?)r$   r%   r5   s    r   is_rootzSyntaxTreeNode.is_root~   s     J4$"455r   c                *    t          | j                  S )zIs this node nested?.

        Returns `True` if the node represents a `Token` pair and tokens in the
        sequence between them, where `Token.nesting` of the first `Token` in
        the pair is 1 and nesting of the other `Token` is -1.
        )r   r%   r5   s    r   	is_nestedzSyntaxTreeNode.is_nested   s     D&'''r   Sequence[_NodeType]c                .    | j         s| gS | j         j        S )z]Get siblings of the node.

        Gets the whole group of siblings, including self.
        )rU   r,   r5   s    r   siblingszSyntaxTreeNode.siblings   s      { 	6M{##r   c                    | j         rdS | j        r| j        j        S | j        sJ | j        j        j                            d          S )a  Get a string type of the represented syntax.

        - "root" for root nodes
        - `Token.type` if the node represents an unnested token
        - `Token.type` of the opening token, with "_open" suffix stripped, if
            the node represents a nester token pair
        rH   _open)rX   r$   r4   r%   r   removesuffixr5   s    r   r4   zSyntaxTreeNode.type   sS     < 	6: 	#:?"!!!!!).;;GDDDr   c                    | j                             |           }|dz   t          | j                   k     r| j         |dz            S dS )zlGet the next node in the sequence of siblings.

        Returns `None` if this is the last sibling.
        r
   N)r]   indexr*   r-   
self_indexs     r   next_siblingzSyntaxTreeNode.next_sibling   sH     ]((..
>C....=a00tr   c                l    | j                             |           }|dz
  dk    r| j         |dz
           S dS )zqGet the previous node in the sequence of siblings.

        Returns `None` if this is the first sibling.
        r
   r   N)r]   rb   rc   s     r   previous_siblingzSyntaxTreeNode.previous_sibling   s>     ]((..
>Q=a00tr   c                |     t          |           |d          }| |_        | j                            |           dS )zMake a child node for `self`.Fr   N)r4   rU   r,   rI   )r-   r   rJ   s      r   
_add_childzSyntaxTreeNode._add_child   sA    
 T

6u555U#####r   c                   t          t          |                    }|r|                                }|j        s|                     |g           4|j        dk    rt          d          |g}d}|r9|r7|                                }|                    |           ||j        z  }|r|7|rt          d|d                    |                     |           |dS dS )zgConvert the token stream to a tree structure and set the resulting
        nodes as children of `self`.r
   zInvalid token nestingzunclosed tokens starting r   N)listreversedpopr+   ri   r)   rI   )r-   r   reversed_tokensr$   nested_tokensr+   s         r   r(   z(SyntaxTreeNode._set_children_from_tokens   s#    x//00 	+#''))E= (((}!! !8999"GMG! )g )'++--$$U+++5=( " )g )  Q !O]1=M!O!OPPPOOM***%  	+ 	+ 	+ 	+ 	+r      Fr   indent	show_text_currentrr   rs   rt   c          	        d|z  }|d| j          z   }| j        sC| j        r<|dd                    d | j                                        D                       z   z  }|dz  }|r=| j        s6| j         dv r-| j        r&|dt          j        | j        |d|z  z             z   z  }| j        D ]#}|d|	                    ||||z             z   z  }$|S )z'Create an XML style string of the tree. <c              3  *   K   | ]\  }}| d |V  dS )=Nr   ).0kvs      r   	<genexpr>z(SyntaxTreeNode.pretty.<locals>.<genexpr>   s0      "O"ODAqa<<!<<"O"O"O"O"O"Or   >)texttext_special
rq   )
r4   rX   attrsjoinitemscontenttextwraprr   r,   pretty)r-   rr   rs   rt   prefixr   rJ   s          r   r   zSyntaxTreeNode.pretty   s    xDI'| 	P
 	PC#(("O"ODJ<L<L<N<N"O"O"OOOOOD	PL	P 	555 6 D8?4<#,9NOOOOD] 	 	ED5<<X=N (    DD r   include_selfr    Generator[_NodeType, None, None]c             #  b   K   |r| V  | j         D ]}|                    d          E d{V  dS )zRecursively yield all descendant nodes in the tree starting at self.

        The order mimics the order of the underlying linear token
        stream (i.e. depth first).
        Tr   N)r,   walk)r-   r   rJ   s      r   r   zSyntaxTreeNode.walk   s]        	JJJ] 	5 	5Ezztz4444444444	5 	5r   r   c                b    | j         r| j         S | j        r| j        j        S t          d          )z\Return the `Token` that is used as the data source for the
        properties defined below.z.Root node does not have the accessed attribute)r$   r%   r   AttributeErrorr5   s    r   _attribute_tokenzSyntaxTreeNode._attribute_token
  s<     : 	: 	.%--MNNNr   c                4    |                                  j        S )zhtml tag name, e.g. "p" )r   tagr5   s    r   r   zSyntaxTreeNode.tag  s     $$&&**r   dict[str, str | int | float]c                4    |                                  j        S )zHtml attributes.)r   r   r5   s    r   r   zSyntaxTreeNode.attrs       $$&&,,r   nameNone | str | int | floatc                P    |                                                      |          S )z@Get the value of attribute `name`, or null if it does not exist.)r   attrGet)r-   r   s     r   r   zSyntaxTreeNode.attrGet  s"    $$&&..t444r   tuple[int, int] | Nonec                Z    |                                  j        }|rt          |          S dS )z8Source map info. Format: `tuple[ line_begin, line_end ]`N)r   maptuple)r-   map_s     r   r   zSyntaxTreeNode.map!  s1     $$&&* 	;;tr   c                4    |                                  j        S )z(nesting level, the same as `state.level`)r   levelr5   s    r   r   zSyntaxTreeNode.level*  r   r   c                4    |                                  j        S )z]In a case of self-closing tag (code, html, fence, etc.), it
        has contents of this tag.)r   r   r5   s    r   r   zSyntaxTreeNode.content/  s     $$&&..r   c                4    |                                  j        S )z5'*' or '_' for emphasis, fence string for fence, etc.)r   markupr5   s    r   r   zSyntaxTreeNode.markup5  s     $$&&--r   c                4    |                                  j        S )zfence infostring)r   infor5   s    r   r   zSyntaxTreeNode.info:       $$&&++r   dict[Any, Any]c                4    |                                  j        S )z/A place for plugins to store an arbitrary data.)r   metar5   s    r   r   zSyntaxTreeNode.meta?  r   r   c                4    |                                  j        S )z5True for block-level tokens, false for inline tokens.)r   blockr5   s    r   r   zSyntaxTreeNode.blockD  r   r   c                4    |                                  j        S )zbIf it's true, ignore this element when rendering.
        Used for tight lists to hide paragraphs.)r   hiddenr5   s    r   r   zSyntaxTreeNode.hiddenI  s     $$&&--r   N)r   )r   r   r   r   r    r!   )r    r0   )r-   r   r7   r8   r    r   )r-   r   r7   r=   r    r>   )r-   r   r7   r@   r    rA   )r-   r   r    rC   )r-   r   r    r>   )r-   r   rO   r>   r    r!   )r-   r   r    rR   )r-   r   rO   rR   r    r!   )r    r   )r-   r   r    r[   )r   r   r    r!   )rr   r8   rs   r   rt   r8   r    r0   )r-   r   r   r   r    r   )r    r   )r    r   )r   r0   r    r   )r    r   )r    r8   )r    r   )#r   r   r   __doc__r/   r6   r	   r<   rL   propertyr,   setterrU   rX   rZ   r]   r4   re   rg   ri   r(   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r      s       
 
 )+(9CG(9 (9 (9 (9 (9 (9T5 5 5 5 AAA XAIII XI# # # #   (    X _   _    X ]   ] 6 6 6 X6 ( ( ( X( $ $ $ X$ E E E XE    X    X$ $ $ $+ + + +2  !E1     . 265 5 5 5 5 5,O O O O + + + X+ - - - X-5 5 5 5    X - - - X- / / / X/
 . . . X. , , , X, , , , X, - - - X- . . . X. . .r   )r   
__future__r   collections.abcr   r   r   typingr   r   r   r	   r$   r   r   r   r   r   r   r   <module>r      s    
 # " " " " " / / / / / / / /  5 5 5 5 5 5 5 5 5 5 5 5          J   
 GK'7888	v. v. v. v. v. v. v. v. v. v.r   