Ë
    éÿæig+  ã                  óŽ   — 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__© ó    úe/Volumes/fast/ai/experiments/voice-extract-mac/.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__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›   ø€ Ø�y‰y˜FÒ"Ø!Ÿ]œ]�EÙ,¨U°JÕ?ñ +à—’Ø×!Ñ! $§*¡*Õ-à×)Ò)Ð)Ð)Ø×!Ñ! $×"4Ñ"4×"<Ñ"<Ô=Ø!Ÿ]œ]�EÙ,¨U°JÕ?ð +à×!Ñ! $×"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   € ð —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.
        )rL   r'   r0   s    r   ÚsiblingszSyntaxTreeNode.siblings�   s"   € ð �{Š{Ø�6ˆMØ�{‰{×#Ñ#Ð#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“
˜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&   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à"˜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Ñ<N±D°A°q a S¨¨!¨¤<Ñ<Nùs   ‚Ú>)Ú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‘ˆØ˜!˜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ô   s5   è ø€ ñ ØŠJØ—]”]ˆEØ—z‘z¨t�zÓ4×4Ñ4ñ #Ø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†   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  „ ñ
ð )+ð(9ØCGñ(9Ø%ð(9Ø<@ð(9à	ó(9óT5ð ÚAó ØAàÚIó ØIó#óð( òó ðð ‡_�_òó ðð òó ðð ‡]�]òó ðð ò6ó ð6ð ò(ó ð(ð ò$ó ð$ð òEó ðEð òó ðð òó ðð$àð$ð 
ó$ó+ð2  !°EÈ1ñØðØ-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   