o
    Ù­jf+  ã                   @  sz   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	„ d	e	ƒZe
d
dd�ZG d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                   @  s   e Zd ZU ded< ded< dS )Ú_NesterTokensr
   ÚopeningÚclosingN)Ú__name__Ú
__module__Ú__qualname__Ú__annotations__© r   r   úM/var/www/html/CropPilot/venv/lib/python3.10/site-packages/markdown_it/tree.pyr      s   
 r   Ú	_NodeTypeÚSyntaxTreeNode)Úboundc                   @  sÆ  e Zd ZdZ	deddœdfdd„Zdgdd„Zedhdd„ƒZedidd„ƒZdjdd„Zdkdd„Ze	dldd „ƒZ
e
jdmd"d „ƒZ
e	dnd$d%„ƒZejdod&d%„ƒZe	dpd'd(„ƒZe	dpd)d*„ƒZe	dqd,d-„ƒZe	dgd.d/„ƒZe	dnd0d1„ƒZe	dnd2d3„ƒZdrd4d5„Zdrd6d7„Zd8d9d:d;œdsd?d@„ZddAœdtdDdE„ZdudGdH„Ze	dgdIdJ„ƒZe	dvdLdM„ƒZdwdPdQ„Ze	dxdSdT„ƒZe	dydUdV„ƒZe	dgdWdX„ƒZe	dgdYdZ„ƒZe	dgd[d\„ƒZe	dzd^d_„ƒZ e	dpd`da„ƒZ!e	dpdbdc„ƒZ"ddS ){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                C  s¢   d| _ d| _d| _g | _|r|  |¡ dS |stdƒ‚t|ƒdkr<|d }|jr,tdƒ‚|| _ |jr:|  |j¡ dS dS t	|d |d ƒ| _|  |dd… ¡ dS )zƒInitialize 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_tokenr   r   r   Ú__init__$   s.   
ÿÿÿzSyntaxTreeNode.__init__Ústrc                 C  s   t | ƒj› d| j › d�S )Nú(ú))Útyper   ©r(   r   r   r   Ú__repr__N   s   zSyntaxTreeNode.__repr__r(   r   ÚitemÚintc                 C  ó   d S ©Nr   ©r(   r1   r   r   r   Ú__getitem__Q   ó   zSyntaxTreeNode.__getitem__Úsliceúlist[_NodeType]c                 C  r3   r4   r   r5   r   r   r   r6   T   r7   úint | sliceú_NodeType | list[_NodeType]c                 C  s
   | j | S r4   )r'   r5   r   r   r   r6   W   s   
úlist[Token]c                   s    d
‡ fdd„‰ g }ˆ | |ƒ |S )z Recover the linear token stream.Únoder   Ú
token_listr<   r   r   c                   sz   | j dkr| jD ]}ˆ ||ƒ qd S | jr| | j¡ d S | js"J ‚| | jj¡ | jD ]}ˆ ||ƒ q,| | jj¡ d S )NÚroot)r.   r'   r   Úappendr    r   r   )r=   r>   Úchild©Úrecursive_collect_tokensr   r   rC   ]   s   

ÿ

z:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokensN)r=   r   r>   r<   r   r   r   )r(   r   r   rB   r   Ú	to_tokensZ   s   
zSyntaxTreeNode.to_tokensc                 C  ó   | j S r4   ©r"   r/   r   r   r   r'   n   ó   zSyntaxTreeNode.childrenÚvaluec                 C  ó
   || _ d S r4   rF   ©r(   rH   r   r   r   r'   r   ó   
ú_NodeType | Nonec                 C  rE   r4   ©r!   r/   r   r   r   Úparentv   rG   zSyntaxTreeNode.parentc                 C  rI   r4   rM   rJ   r   r   r   rN   z   rK   c                 C  s   | j p| j S )z Is the node a special root node?)r   r    r/   r   r   r   Úis_root~   s   zSyntaxTreeNode.is_rootc                 C  s
   t | jƒS )zùIs 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    r/   r   r   r   Ú	is_nestedƒ   s   
zSyntaxTreeNode.is_nestedúSequence[_NodeType]c                 C  s   | j s| gS | j jS )z]Get siblings of the node.

        Gets the whole group of siblings, including self.
        )rN   r'   r/   r   r   r   Úsiblings�   s   zSyntaxTreeNode.siblingsc                 C  s2   | 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
        r?   Ú_open)rO   r   r.   r    r   Úremovesuffixr/   r   r   r   r.   —   s   	
zSyntaxTreeNode.typec                 C  s0   | j  | ¡}|d t| j ƒk r| j |d  S dS )zlGet the next node in the sequence of siblings.

        Returns `None` if this is the last sibling.
        r	   N)rR   Úindexr%   ©r(   Ú
self_indexr   r   r   Únext_sibling§   s   zSyntaxTreeNode.next_siblingc                 C  s*   | j  | ¡}|d dkr| j |d  S dS )zqGet the previous node in the sequence of siblings.

        Returns `None` if this is the first sibling.
        r	   r   N)rR   rU   rV   r   r   r   Úprevious_sibling²   s   zSyntaxTreeNode.previous_siblingc                 C  s&   t | ƒ|dd�}| |_| j |¡ dS )zMake a child node for `self`.Fr   N)r.   rN   r'   r@   )r(   r   rA   r   r   r   Ú
_add_child½   s   zSyntaxTreeNode._add_childc                 C  s    t t|ƒƒ}|rN| ¡ }|js|  |g¡ q|jdkrtdƒ‚|g}d}|r:|r:| ¡ }| |¡ ||j7 }|r:|s(|rEtd|d › �ƒ‚|  |¡ |s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&   rZ   r$   r@   )r(   r   Úreversed_tokensr   Únested_tokensr&   r   r   r   r#   Æ   s&   


ý
îz(SyntaxTreeNode._set_children_from_tokensé   Fr   ©ÚindentÚ	show_textÚ_currentrb   rc   rd   c                C  s²   d| }|d| j › � }| js#| jr#|dd dd„ | j ¡ D ƒ¡ 7 }|d7 }|rC| jsC| j dv rC| jrC|dt | j|d|  ¡ 7 }| jD ]}|d|j	|||| d� 7 }qF|S )	z'Create an XML style string of the tree.ú ú<c                 s  s"   � | ]\}}|› d |›�V  qdS )ú=Nr   )Ú.0ÚkÚvr   r   r   Ú	<genexpr>å   s   €  z(SyntaxTreeNode.pretty.<locals>.<genexpr>ú>)ÚtextÚtext_specialÚ
ra   )
r.   rO   ÚattrsÚjoinÚitemsÚcontentÚtextwraprb   r'   Úpretty)r(   rb   rc   rd   Úprefixrm   rA   r   r   r   ru   Þ   s$   "ÿþ
ÿ

ÿzSyntaxTreeNode.pretty©Úinclude_selfrx   ú Generator[_NodeType, None, None]c                c  s.   � |r| V  | j D ]}|jdd�E dH  q	dS )z³Recursively 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).
        Trw   N)r'   Úwalk)r(   rx   rA   r   r   r   rz   ô   s   €
ÿzSyntaxTreeNode.walkr
   c                 C  s"   | 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   ÚAttributeErrorr/   r   r   r   Ú_attribute_token
  s
   zSyntaxTreeNode._attribute_tokenc                 C  ó
   |   ¡ jS )zhtml tag name, e.g. "p")r|   Útagr/   r   r   r   r~     ó   
zSyntaxTreeNode.tagúdict[str, str | int | float]c                 C  r}   )zHtml attributes.)r|   rp   r/   r   r   r   rp     r   zSyntaxTreeNode.attrsÚnameúNone | str | int | floatc                 C  s   |   ¡  |¡S )z@Get the value of attribute `name`, or null if it does not exist.)r|   ÚattrGet)r(   r�   r   r   r   rƒ     s   zSyntaxTreeNode.attrGetútuple[int, int] | Nonec                 C  s   |   ¡ j}|rt|ƒS dS )z8Source map info. Format: `tuple[ line_begin, line_end ]`N)r|   ÚmapÚtuple)r(   Úmap_r   r   r   r…   !  s   
zSyntaxTreeNode.mapc                 C  r}   )z(nesting level, the same as `state.level`)r|   Úlevelr/   r   r   r   rˆ   *  r   zSyntaxTreeNode.levelc                 C  r}   )z]In a case of self-closing tag (code, html, fence, etc.), it
        has contents of this tag.)r|   rs   r/   r   r   r   rs   /  ó   
zSyntaxTreeNode.contentc                 C  r}   )z5'*' or '_' for emphasis, fence string for fence, etc.)r|   Úmarkupr/   r   r   r   rŠ   5  r   zSyntaxTreeNode.markupc                 C  r}   )zfence infostring)r|   Úinfor/   r   r   r   r‹   :  r   zSyntaxTreeNode.infoúdict[Any, Any]c                 C  r}   )z/A place for plugins to store an arbitrary data.)r|   Úmetar/   r   r   r   r�   ?  r   zSyntaxTreeNode.metac                 C  r}   )z5True for block-level tokens, false for inline tokens.)r|   Úblockr/   r   r   r   rŽ   D  r   zSyntaxTreeNode.blockc                 C  r}   )zbIf it's true, ignore this element when rendering.
        Used for tight lists to hide paragraphs.)r|   Úhiddenr/   r   r   r   r�   I  r‰   zSyntaxTreeNode.hiddenN)r   )r   r   r   r   r   r   )r   r+   )r(   r   r1   r2   r   r   )r(   r   r1   r8   r   r9   )r(   r   r1   r:   r   r;   )r(   r   r   r<   )r(   r   r   r9   )r(   r   rH   r9   r   r   )r(   r   r   rL   )r(   r   rH   rL   r   r   )r   r   )r(   r   r   rQ   )r   r   r   r   )rb   r2   rc   r   rd   r2   r   r+   )r(   r   rx   r   r   ry   )r   r
   )r   r€   )r�   r+   r   r‚   )r   r„   )r   r2   )r   rŒ   )#r   r   r   Ú__doc__r*   r0   r   r6   rD   Úpropertyr'   ÚsetterrN   rO   rP   rR   r.   rX   rY   rZ   r#   ru   rz   r|   r~   rp   rƒ   r…   rˆ   rs   rŠ   r‹   r�   rŽ   r�   r   r   r   r   r      sz    ÿÿ
*

		



	ÿÿ
	
)r�   Ú
__future__r   Úcollections.abcr   r   rt   Útypingr   r   r   r   r   r
   r   r   r   r   r   r   r   Ú<module>   s    