
    Mhg+                        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y)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<   y)_NesterTokensr   openingclosingN)__name__
__module____qualname____annotations__     h/var/www/pru.catia.catastroantioquia-mas.com/valormasv2/lib/python3.12/site-packages/markdown_it/tree.pyr   r      s    NNr   r   	_NodeTypeSyntaxTreeNode)boundc                  X   e Zd ZdZ	 d*dd	 	 	 	 	 d+dZd,dZed-d       Zed.d       Zd/dZd0d	Ze	d1d
       Z
e
j                  d2d       Z
e	d3d       Zej                  d4d       Ze	d5d       Ze	d5d       Ze	d6d       Ze	d,d       Ze	d3d       Ze	d3d       Z	 	 	 	 d7dZd7dZdddd	 	 	 	 	 	 	 d8dZdd	 	 	 	 	 d9dZd:dZe	d,d       Ze	d;d       Zd<d Ze	d=d!       Ze	d>d"       Ze	d,d#       Ze	d,d$       Ze	d,d%       Ze	d?d&       Z e	d5d'       Z!e	d5d(       Z"y))@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
    Tcreate_rootc                  d| _         d| _        d| _        g | _        |r| j	                  |       y|st        d      t        |      dk(  rL|d   }|j                  rt        d      || _         |j                  r| j	                  |j                         yyt        |d   |d         | _        | j	                  |dd        y)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   )selftokensr   inline_tokens       r   __init__zSyntaxTreeNode.__init__$   s     $(
 48 ! %'**62+  [A!!9L## Q  &DJ$$..|/D/DE % "/vay&*!ED**6!B<8r   c                L    t        |       j                   d| j                    dS )N())typer   r(   s    r   __repr__zSyntaxTreeNode.__repr__N   s$    t*%%&a		{!44r   c                     y Nr   r(   items     r   __getitem__zSyntaxTreeNode.__getitem__Q   s    >Ar   c                     y r3   r   r4   s     r   r6   zSyntaxTreeNode.__getitem__T   s    FIr   c                     | j                   |   S r3   )r'   r4   s     r   r6   zSyntaxTreeNode.__getitem__W   s    }}T""r   c                *    dfdg } | |       |S )z Recover the linear token stream.c                   | j                   dk(  r| j                  D ]  } ||        y | j                  r|j                  | j                         y | j                  sJ |j                  | j                  j
                         | j                  D ]  } ||        |j                  | j                  j                         y )Nroot)r/   r'   r   appendr    r   r   )node
token_listchildrecursive_collect_tokenss      r   r@   z:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokens]   s    yyF"!]] @E,UJ?@!!$**-))))!!$"4"4"<"<=!]] @E,UJ?@!!$"4"4"<"<=r   )r=   r   r>   list[Token]returnNoner   )r(   r)   r@   s     @r   	to_tokenszSyntaxTreeNode.to_tokensZ   s    	> ! v.r   c                    | j                   S r3   r"   r0   s    r   r'   zSyntaxTreeNode.childrenn   s    ~~r   c                    || _         y r3   rF   r(   values     r   r'   zSyntaxTreeNode.childrenr   s	    r   c                    | j                   S r3   r!   r0   s    r   parentzSyntaxTreeNode.parentv   s    ||r   c                    || _         y r3   rK   rH   s     r   rL   zSyntaxTreeNode.parentz   s	    r   c                8    | j                   xs | j                   S )z Is the node a special root node?)r   r    r0   s    r   is_rootzSyntaxTreeNode.is_root~   s     JJ4$"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.
        )boolr    r0   s    r   	is_nestedzSyntaxTreeNode.is_nested   s     D&&''r   c                L    | j                   s| gS | j                   j                  S )z]Get siblings of the node.

        Gets the whole group of siblings, including self.
        )rL   r'   r0   s    r   siblingszSyntaxTreeNode.siblings   s"     {{6M{{###r   c                    | j                   ry| j                  r| j                  j                  S | j                  sJ | 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
        r;   _open)rO   r   r/   r    r   removesuffixr0   s    r   r/   zSyntaxTreeNode.type   sU     <<::::??"!!!!!!))..;;GDDr   c                    | j                   j                  |       }|dz   t        | j                         k  r| j                   |dz      S y)zlGet the next node in the sequence of siblings.

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

        Returns `None` if this is the first sibling.
        r
   r   N)rT   rY   rZ   s     r   previous_siblingzSyntaxTreeNode.previous_sibling   s:     ]]((.
>Q==a00r   c                n     t        |       |d      }| |_        | j                  j                  |       y)zMake a child node for `self`.Fr   N)r/   rL   r'   r<   )r(   r)   r?   s      r   
_add_childzSyntaxTreeNode._add_child   s/    
 T
6u5U#r   c                   t        t        |            }|r|j                         }|j                  s| j	                  |g       1|j                  dk7  rt        d      |g}d}|r7|r5|j                         }|j                  |       ||j                  z  }|r|r5|rt        d|d          | j	                  |       |ryy)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&   r`   r$   r<   )r(   r)   reversed_tokensr   nested_tokensr&   s         r   r#   z(SyntaxTreeNode._set_children_from_tokens   s     x/0#'')E==(}}! !899"GMG!g'++-$$U+5==( "g  #<]1=M<N!OPPOOM*% r      Fr   indent	show_text_currentc          	        d|z  }|d| j                    z   }| j                  sB| j                  r6|ddj                  d | j                  j	                         D              z   z  }|dz  }|rR| j                  sF| j                   dv r8| j
                  r,|dt        j                  | j
                  |d|z  z         z   z  }| j                  D ]  }|d|j                  ||||z         z   z  }! |S )z'Create an XML style string of the tree. <c              3  0   K   | ]  \  }}| d |  yw)=Nr   ).0kvs      r   	<genexpr>z(SyntaxTreeNode.pretty.<locals>.<genexpr>   s     "ODAqaS!<"Os   >)texttext_special
rh   )
r/   rO   attrsjoinitemscontenttextwrapri   r'   pretty)r(   ri   rj   rk   prefixrv   r?   s          r   r~   zSyntaxTreeNode.pretty   s     x!DII;'||

C#(("ODJJ<L<L<N"OOOODLL		55D8??4<<#,9NOOOD]] 	ED5<<X=N (   D	 r   include_selfc             #  r   K   |r|  | j                   D ]  }|j                  d      E d{     y7 w)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   r?   s      r   r   zSyntaxTreeNode.walk   s:      J]] 	5Ezztz444	54s   +757c                    | 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   AttributeErrorr0   s    r   _attribute_tokenzSyntaxTreeNode._attribute_token
  s<     ::::%%---MNNr   c                6    | j                         j                  S )zhtml tag name, e.g. "p" )r   tagr0   s    r   r   zSyntaxTreeNode.tag  s     $$&***r   c                6    | j                         j                  S )zHtml attributes.)r   ry   r0   s    r   ry   zSyntaxTreeNode.attrs       $$&,,,r   c                @    | j                         j                  |      S )z@Get the value of attribute `name`, or null if it does not exist.)r   attrGet)r(   names     r   r   zSyntaxTreeNode.attrGet  s    $$&..t44r   c                R    | j                         j                  }|rt        |      S y)z8Source map info. Format: `tuple[ line_begin, line_end ]`N)r   maptuple)r(   map_s     r   r   zSyntaxTreeNode.map!  s(     $$&**;r   c                6    | j                         j                  S )z(nesting level, the same as `state.level`)r   levelr0   s    r   r   zSyntaxTreeNode.level*  r   r   c                6    | j                         j                  S )z]In a case of self-closing tag (code, html, fence, etc.), it
        has contents of this tag.)r   r|   r0   s    r   r|   zSyntaxTreeNode.content/  s     $$&...r   c                6    | j                         j                  S )z5'*' or '_' for emphasis, fence string for fence, etc.)r   markupr0   s    r   r   zSyntaxTreeNode.markup5  s     $$&---r   c                6    | j                         j                  S )zfence infostring)r   infor0   s    r   r   zSyntaxTreeNode.info:       $$&+++r   c                6    | j                         j                  S )z/A place for plugins to store an arbitrary data.)r   metar0   s    r   r   zSyntaxTreeNode.meta?  r   r   c                6    | j                         j                  S )z5True for block-level tokens, false for inline tokens.)r   blockr0   s    r   r   zSyntaxTreeNode.blockD  r   r   c                6    | j                         j                  S )zbIf it's true, ignore this element when rendering.
        Used for tight lists to hide paragraphs.)r   hiddenr0   s    r   r   zSyntaxTreeNode.hiddenI  s     $$&---r   N)r   )r)   Sequence[Token]r   rQ   rB   rC   )rB   str)r(   r   r5   intrB   r   )r(   r   r5   slicerB   list[_NodeType])r(   r   r5   zint | slicerB   z_NodeType | list[_NodeType])r(   r   rB   rA   )r(   r   rB   r   )r(   r   rI   r   rB   rC   )r(   r   rB   _NodeType | None)r(   r   rI   r   rB   rC   )rB   rQ   )r(   r   rB   zSequence[_NodeType])r)   r   rB   rC   )ri   r   rj   rQ   rk   r   rB   r   )r(   r   r   rQ   rB   z Generator[_NodeType, None, None])rB   r   )rB   zdict[str, str | int | float])r   r   rB   zNone | str | int | float)rB   ztuple[int, int] | None)rB   r   )rB   zdict[Any, Any])#r   r   r   __doc__r+   r1   r	   r6   rD   propertyr'   setterrL   rO   rR   rT   r/   r\   r^   r`   r#   r~   r   r   r   ry   r   r   r   r|   r   r   r   r   r   r   r   r   r   r      sp   
 )+(9CG(9%(9<@(9	(9T5 A AI I#(   __    ]]  6 6 ( ( $ $ E E    $$ 
$+2  !E1-1EH	. 2655*.5	)5,O + + - -5   - - / /
 . . , , , , - - . .r   )r   
__future__r   collections.abcr   r   r}   typingr   r   r   r	   r   r   r   r   r   r   r   r   <module>r      sE   
 # /  5 5 J 
 K'78	v. v.r   