Ë
    RPf�,  ã                  ó–   — 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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__© ó    úJ/var/www/fastapitest/venv/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)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   )ÚselfÚtokensr   Úinline_tokens       r   Ú__init__zSyntaxTreeNode.__init__#   sØ   € ð $(ˆŒ
ð 48ˆÔð !ˆŒð %'ˆŒáØ×*Ñ*¨6Ô2ØáÜð+óð ô �‹[˜AÒØ! !™9ˆLØ×#Ò#Ü ØQóð ð &ˆDŒJØ×$Ò$Ø×.Ñ.¨|×/DÑ/DÕEð %ô "/¨v°a©y¸&À¹*Ó!EˆDÔØ×*Ñ*¨6°!°B¨<Õ8r   c                óL   — t        | «      j                  › d| j                   › d�S )Nú(ú))Útyper   ©r(   s    r   Ú__repr__zSyntaxTreeNode.__repr__M   s$   € Ü�t“*×%Ñ%Ð& a¨¯	©	 {°!Ð4Ð4r   c                 ó   — y ©Nr   ©r(   Úitems     r   Ú__getitem__zSyntaxTreeNode.__getitem__P   ó   € àr   c                 ó   — y r3   r   r4   s     r   r6   zSyntaxTreeNode.__getitem__T   r7   r   c                ó    — | j                   |   S r3   )r'   r4   s     r   r6   zSyntaxTreeNode.__getitem__X   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   rA   z:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokens^   s©   ø€ Ø�y‰y˜FÒ"Ø!Ÿ]™]ò @�EÙ,¨U°JÕ?ñ@à—’Ø×!Ñ! $§*¡*Õ-à×)Ò)Ð)Ð)Ø×!Ñ! $×"4Ñ"4×"<Ñ"<Ô=Ø!Ÿ]™]ò @�EÙ,¨U°JÕ?ð@à×!Ñ! $×"4Ñ"4×"<Ñ"<Õ=r   )r>   r   r?   úlist[Token]ÚreturnÚNoner   )r(   r)   rA   s     @r   Ú	to_tokenszSyntaxTreeNode.to_tokens[   s   ø€ õ	>ð !ˆÙ   vÔ.Øˆr   c                ó   — | j                   S r3   ©r"   r0   s    r   r'   zSyntaxTreeNode.childreno   s   € à�~‰~Ðr   c                ó   — || _         y r3   rG   ©r(   Úvalues     r   r'   zSyntaxTreeNode.childrens   s	   € àˆ�r   c                ó   — | j                   S r3   ©r!   r0   s    r   ÚparentzSyntaxTreeNode.parentw   s   € à�|‰|Ðr   c                ó   — || _         y r3   rL   rI   s     r   rM   zSyntaxTreeNode.parent{   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   € ð —J‘JÒ4 $×"4Ñ"4Ð5Ð5r   c                ó,   — 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.
        )Ú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.
        )rM   r'   r0   s    r   ÚsiblingszSyntaxTreeNode.siblingsŽ   s"   € ð �{Š{Ø�6ˆMØ�{‰{×#Ñ#Ð#r   c                óÐ   — | j                   ry| j                  r| j                  j                  S | j                  sJ ‚t	        | 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)rP   r   r/   r    Ú_removesuffixr   r0   s    r   r/   zSyntaxTreeNode.type˜   sQ   € ð �<Š<ØØ�:Š:Ø—:‘:—?‘?Ð"Ø×!Ò!Ð!Ð!Ü˜T×/Ñ/×7Ñ7×<Ñ<¸gÓFÐFr   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)rU   Ú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)rU   rZ   r[   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/   rM   r'   r=   )r(   r)   r@   s      r   Ú
_add_childzSyntaxTreeNode._add_child¾   s/   € ð
 ”�T“
˜6¨uÔ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&   ra   r$   r=   )r(   r)   Úreversed_tokensr   Únested_tokensr&   s         r   r#   z(SyntaxTreeNode._set_children_from_tokensÇ   sÅ   € ô œx¨Ó/Ó0ˆÙØ#×'Ñ'Ó)ˆEà—=’=Ø—‘  Ô(ØØ�}‰} Ò!Ü Ð!8Ó9Ð9à"˜GˆMØˆGÙ!¡gØ'×+Ñ+Ó-�Ø×$Ñ$ UÔ+Ø˜5Ÿ=™=Ñ(�ñ "¢gñ Ü Ð#<¸]È1Ñ=MÐ<NÐ!OÓPÐPà�O‰O˜MÔ*ô% 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   è ø€ Ò"O±D°A°q a S¨¨!¨¤<Ñ"Oùs   ‚ú>)ÚtextÚtext_specialú
ri   )
r/   rP   ÚattrsÚjoinÚitemsÚcontentÚtextwraprj   r'   Úpretty)r(   rj   rk   rl   Úprefixrw   r@   s          r   r   zSyntaxTreeNode.prettyß   sî   € ð �x‘ˆØ˜!˜DŸI™I˜;˜Ñ'ˆØ�|Š| §
¢
Ø�C˜#Ÿ(™(Ñ"O¸D¿J¹J×<LÑ<LÓ<NÔ"OÓOÑOÑOˆDØ�‰ˆáØ—L’LØ—	‘	Ð5Ñ5Ø—’à�Dœ8Ÿ?™?¨4¯<©<¸À#ÈÁ,Ñ9NÓOÑOÑOˆDØ—]‘]ò 	ˆEØ�D˜5Ÿ<™<Ø¨¸XÈÑ=Nð (ó ñ ñ ‰Dð	ð ˆr   ©Úinclude_selfc             #  ór   K  — |r| –— | j                   D ]  }|j                  d¬«      E d{  –—†  Œ y7 Œ­w)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).
        Tr�   N)r'   Úwalk)r(   r‚   r@   s      r   r„   zSyntaxTreeNode.walkõ   s:   è ø€ ñ ØŠJØ—]‘]ò 	5ˆEØ—z‘z¨t�zÓ4×4Ñ4ñ	5Ø4ús   ‚+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‡   rz   r0   s    r   rz   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.content0  s   € ð ×$Ñ$Ó&×.Ñ.Ð.r   c                ó6   — | j                  «       j                  S )z5'*' or '_' for emphasis, fence string for fence, etc.)r‡   Úmarkupr0   s    r   r—   zSyntaxTreeNode.markup6  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.blockE  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.hiddenJ  s   € ð ×$Ñ$Ó&×-Ñ-Ð-r   N)r   )r)   úSequence[Token]r   rR   rC   rD   )rC   Ústr)r(   r   r5   ÚintrC   r   )r(   r   r5   ÚslicerC   úlist[_NodeType])r(   r   r5   zint | slicerC   z_NodeType | list[_NodeType])r(   r   rC   rB   )r(   r   rC   r¥   )r(   r   rJ   r¥   rC   rD   )r(   r   rC   ú_NodeType | None)r(   r   rJ   r¦   rC   rD   )rC   rR   )r(   r   rC   zSequence[_NodeType])r)   r¡   rC   rD   )rj   r£   rk   rR   rl   r£   rC   r¢   )r(   r   r‚   rR   rC   z Generator[_NodeType, None, None])rC   r   )rC   zdict[str, str | int | float])rŽ   r¢   rC   zNone | str | int | float)rC   ztuple[int, int] | None)rC   r£   )rC   zdict[Any, Any])#r   r   r   Ú__doc__r+   r1   r	   r6   rE   Úpropertyr'   ÚsetterrM   rP   rS   rU   r/   r]   r_   ra   r#   r   r„   r‡   r‰   rz   r�   r�   r”   r}   r—   r™   rœ   rž   r    r   r   r   r   r      sz  „ ñ
ð )+ð(9ØCGñ(9Ø%ð(9Ø<@ð(9à	ó(9óT5ð òó ðð òó ðó#óð( òó ðð ‡_�_òó ðð òó ðð ‡]�]òó ðð ò6ó ð6ð ò(ó ð(ð ò$ó ð$ð òGó ðGð òó ðð òó ðð$àð$ð 
ó$ó+ð2  !°EÈ1ñØðØ-1ðØEHðà	óð. 26ñ5Øð5Ø*.ð5à	)ó5ó,Oð ò+ó ð+ð ò-ó ð-ó5ð òó ðð ò-ó ð-ð ò/ó ð/ð
 ò.ó ð.ð ò,ó ð,ð ò,ó ð,ð ò-ó ð-ð ò.ó ñ.r   c                óJ   — |r | j                  |«      r| dt        |«        S | S )z�Remove a suffix from a string.

    Replace this with str.removesuffix() from stdlib when minimum Python
    version is 3.9.
    N)Úendswithr%   )ÚstringÚsuffixs     r   rX   rX   Q  s*   € ñ �&—/‘/ &Ô)Ø�nœ˜V›˜Ð%Ð%Ø€Mr   )r¬   r¢   r­   r¢   rC   r¢   )r§   Ú
__future__r   Úcollections.abcr   r   r~   Útypingr   r   r   r	   r   r   r   r   r   rX   r   r   r   ú<module>r±      sK   ðñõ #ç /Û ß 5Ó 5å ô�Jô ñ
 �KÐ'7Ô8€	÷x.ñ x.ôv	r   