ó
    ORig+  ã                  óˆ   • S r SSKJr  SSKJrJr  SSKrSSKJrJ	r	J
r
Jr  SSKJr   " S S	\	5      r\
" S
SS9r " S S5      rg)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                  ó*   • \ rS rSr% S\S'   S\S'   Srg)Ú_NesterTokensé   r   ÚopeningÚclosing© N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__annotations__Ú__static_attributes__r   ó    Ú%Lib\site-packages\markdown_it\tree.pyr   r      s   ‡ ØƒNØ†Nr   r   Ú	_NodeTypeÚSyntaxTreeNode)Úboundc                  ó¨  • \ rS rSrSr S,SS.     S-S jjjrS.S jr\S/S j5       r\S0S j5       rS1S	 jrS2S
 jr	\
S3S j5       r\R                  S4S j5       r\
S5S j5       r\R                  S6S j5       r\
S7S j5       r\
S7S j5       r\
S8S j5       r\
S.S j5       r\
S5S j5       r\
S5S j5       r    S9S jrS9S jrSSSS.       S:S jjrSS.     S;S jjrS<S jr\
S.S j5       r\
S=S  j5       rS>S! jr\
S?S" j5       r\
S@S# j5       r\
S.S$ j5       r\
S.S% j5       r\
S.S& j5       r \
SAS' j5       r!\
S7S( j5       r"\
S7S) j5       r#S*r$g+)Br   é   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               ó°  • SU l         SU l        SU l        / U l        U(       a  U R	                  U5        gU(       d  [        S5      e[        U5      S:X  aU  US   nUR                  (       a  [        S5      eX0l         UR                  (       a  U R	                  UR                  5        gg[        US   US   5      U l        U R	                  USS 5        g)zsInitialize 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__ÚSyntaxTreeNode.__init__$   sÖ   € ð $(ˆŒ
ð 48ˆÔð !ˆŒð %'ˆŒæØ×*Ñ*¨6Ô2ØæÜð+óð ô �‹[˜AÓØ! !™9ˆLØ×#×#Ü ØQóð ð &ŒJØ×$×$Ø×.Ñ.¨|×/DÑ/DÕEð %ô "/¨v°a©y¸&À¹*Ó!EˆDÔØ×*Ñ*¨6°!°B¨<Õ8r   c                óL   • [        U 5      R                   SU R                    S3$ )NÚ(Ú))Útyper   ©r,   s    r   Ú__repr__ÚSyntaxTreeNode.__repr__N   s$   € Ü�t“*×%Ñ%Ð& a¨¯	©	 {°!Ð4Ð4r   c                ó   • g ©Nr   ©r,   Úitems     r   Ú__getitem__ÚSyntaxTreeNode.__getitem__Q   s   € Ø>Ar   c                ó   • g r9   r   r:   s     r   r<   r=   T   s   € ØFIr   c                ó    • U R                   U   $ r9   )r+   r:   s     r   r<   r=   W   s   € Ø�}‰}˜TÑ"Ð"r   c                ó,   ^• SU4S jjm/ nT" X5        U$ )z Recover the linear token stream.c                ó¨  >• U R                   S:X  a  U R                   H  nT" X!5        M     g U R                  (       a  UR                  U R                  5        g U R                  (       d   eUR                  U R                  R
                  5        U R                   H  nT" X!5        M     UR                  U R                  R                  5        g )NÚroot)r4   r+   r#   Úappendr$   r   r   )ÚnodeÚ
token_listÚchildÚrecursive_collect_tokenss      €r   rG   Ú:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokens]   s—   ø€ Ø�y‰y˜FÓ"Ø!Ÿ]œ]�EÙ,¨UÖ?ò +à——Ø×!Ñ! $§*¡*Õ-à×)×)Ð)Ð)Ø×!Ñ! $×"4Ñ"4×"<Ñ"<Ô=Ø!Ÿ]œ]�EÙ,¨UÖ?ñ +à×!Ñ! $×"4Ñ"4×"<Ñ"<Õ=r   )rD   r   rE   úlist[Token]ÚreturnÚNoner   )r,   r-   rG   s     @r   Ú	to_tokensÚSyntaxTreeNode.to_tokensZ   s   ø€ ÷	>ð !ˆÙ  Ô.Øˆr   c                ó   • U R                   $ r9   ©r&   r5   s    r   r+   ÚSyntaxTreeNode.childrenn   s   € à�~‰~Ðr   c                ó   • Xl         g r9   rO   ©r,   Úvalues     r   r+   rP   r   s   € à�r   c                ó   • U R                   $ r9   ©r%   r5   s    r   ÚparentÚSyntaxTreeNode.parentv   s   € à�|‰|Ðr   c                ó   • Xl         g r9   rU   rR   s     r   rV   rW   z   s   € à�r   c                óJ   • U R                   =(       d    U R                  (       + $ )z Is the node a special root node?)r#   r$   r5   s    r   Úis_rootÚSyntaxTreeNode.is_root~   s   € ð —J‘J×4 $×"4Ñ"4Ô5Ð5r   c                ó,   • [        U R                  5      $ )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$   r5   s    r   Ú	is_nestedÚSyntaxTreeNode.is_nestedƒ   s   € ô �D×&Ñ&Ó'Ð'r   c                óV   • U R                   (       d  U /$ U R                   R                  $ )zMGet siblings of the node.

Gets the whole group of siblings, including self.
)rV   r+   r5   s    r   ÚsiblingsÚSyntaxTreeNode.siblings�   s"   € ð �{�{Ø�6ˆMØ�{‰{×#Ñ#Ð#r   c                óø   • U R                   (       a  gU R                  (       a  U R                  R                  $ U R                  (       d   eU R                  R                  R                  R                  S5      $ )zð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
rB   Ú_open)rZ   r#   r4   r$   r   Úremovesuffixr5   s    r   r4   ÚSyntaxTreeNode.type—   sU   € ð �<�<ØØ�:�:Ø—:‘:—?‘?Ð"Ø×!×!Ð!Ð!Ø×!Ñ!×)Ñ)×.Ñ.×;Ñ;¸GÓDÐDr   c                ó–   • U R                   R                  U 5      nUS-   [        U R                   5      :  a  U R                   US-      $ g)z\Get the next node in the sequence of siblings.

Returns `None` if this is the last sibling.
r
   N)ra   Úindexr)   ©r,   Ú
self_indexs     r   Únext_siblingÚSyntaxTreeNode.next_sibling§   sC   € ð —]‘]×(Ñ(¨Ó.ˆ
Ø˜‰>œC §¡Ó.Ó.Ø—=‘= ¨a¡Ñ0Ð0Ør   c                óp   • U R                   R                  U 5      nUS-
  S:¼  a  U R                   US-
     $ g)zaGet the previous node in the sequence of siblings.

Returns `None` if this is the first sibling.
r
   r   N)ra   rh   ri   s     r   Úprevious_siblingÚSyntaxTreeNode.previous_sibling²   s:   € ð —]‘]×(Ñ(¨Ó.ˆ
Ø˜‰>˜QÓØ—=‘= ¨a¡Ñ0Ð0Ør   c                óf   • [        U 5      " USS9nXl        U R                  R                  U5        g)zMake a child node for `self`.Fr   N)r4   rV   r+   rC   )r,   r-   rF   s      r   Ú
_add_childÚSyntaxTreeNode._add_child½   s+   € ô
 �T”
˜6¨uÑ5ˆØŒØ�‰×Ñ˜UÕ#r   c                óä  • [        [        U5      5      nU(       aÕ  UR                  5       nUR                  (       d  U R	                  U/5        M<  UR                  S:w  a  [        S5      eU/nSnU(       aF  U(       a?  UR                  5       nUR                  U5        XSR                  -  nU(       a	  U(       a  M?  U(       a  [        SUS    35      eU R	                  U5        U(       a  MÔ  gg)z_Convert 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*   rq   r(   rC   )r,   r-   Úreversed_tokensr#   Únested_tokensr*   s         r   r'   Ú(SyntaxTreeNode._set_children_from_tokensÆ   sÇ   € ô œx¨Ó/Ó0ˆÞØ#×'Ñ'Ó)ˆEà—=—=Ø—‘  Ô(ÙØ�}‰} Ó!Ü Ð!8Ó9Ð9à"˜GˆMØˆGÞ!¦gØ'×+Ñ+Ó-�Ø×$Ñ$ UÔ+ØŸ=™=Ñ(�ö "§g gö Ü Ð#<¸]È1Ñ=MÐ<NÐ!OÓPÐPà�O‰O˜MÔ*÷% Šor   é   Fr   ©ÚindentÚ	show_textÚ_currentc          	     ó  • SU-  nUSU R                    3-   nU R                  (       dG  U R                  (       a6  USSR                  S U R                  R	                  5        5       5      -   -  nUS-  nU(       a_  U R                  (       dN  U R                   S;   a>  U R
                  (       a-  US[        R                  " U R
                  USU-  -   5      -   -  nU R                   H  nUSUR                  XX1-   S9-   -  nM     U$ )z'Create an XML style string of the tree.Ú Ú<c              3  ó6   #   • U  H  u  pU S U< 3v •  M     g7f)Ú=Nr   )Ú.0ÚkÚvs      r   Ú	<genexpr>Ú(SyntaxTreeNode.pretty.<locals>.<genexpr>å   s   é € Ð"OÒ<N±D°A a S¨¨!©¥<Ò<Nùs   ‚Ú>)ÚtextÚtext_specialÚ
r{   )
r4   rZ   ÚattrsÚjoinÚitemsÚcontentÚtextwrapr|   r+   Úpretty)r,   r|   r}   r~   ÚprefixrŠ   rF   s          r   r’   Ú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             #  óz   #   • U(       a  U v •  U R                    H  nUR                  SS9 Sh  v•N   M     g N	7f)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–   rF   s      r   r˜   ÚSyntaxTreeNode.walkô   s4   é € ö ØŠJØ—]”]ˆEØ—z‘z¨t�zÐ4×4Ò4ò #Ù4ùs   ‚-;¯9°
;c                ó    • U R                   (       a  U R                   $ U R                  (       a  U R                  R                  $ [        S5      e)zTReturn 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_tokenÚSyntaxTreeNode._attribute_token
  s<   € ð �:�:Ø—:‘:ÐØ××Ø×%Ñ%×-Ñ-Ð-ÜÐMÓNÐNr   c                ó6   • U R                  5       R                  $ )zhtml tag name, e.g. "p" )rœ   Útagr5   s    r   rŸ   ÚSyntaxTreeNode.tag  s   € ð ×$Ñ$Ó&×*Ñ*Ð*r   c                ó6   • U R                  5       R                  $ )zHtml attributes.)rœ   r�   r5   s    r   r�   ÚSyntaxTreeNode.attrs  ó   € ð ×$Ñ$Ó&×,Ñ,Ð,r   c                ó@   • U R                  5       R                  U5      $ )z@Get the value of attribute `name`, or null if it does not exist.)rœ   ÚattrGet)r,   Únames     r   r¥   ÚSyntaxTreeNode.attrGet  s   € à×$Ñ$Ó&×.Ñ.¨tÓ4Ð4r   c                ó\   • U R                  5       R                  nU(       a  [        U5      $ g)z8Source map info. Format: `tuple[ line_begin, line_end ]`N)rœ   ÚmapÚtuple)r,   Úmap_s     r   r©   ÚSyntaxTreeNode.map!  s(   € ð ×$Ñ$Ó&×*Ñ*ˆÞä˜“;ÐØr   c                ó6   • U R                  5       R                  $ )z(nesting level, the same as `state.level`)rœ   Úlevelr5   s    r   r®   ÚSyntaxTreeNode.level*  r£   r   c                ó6   • U R                  5       R                  $ )zUIn a case of self-closing tag (code, html, fence, etc.), it
has contents of this tag.)rœ   r�   r5   s    r   r�   ÚSyntaxTreeNode.content/  s   € ð ×$Ñ$Ó&×.Ñ.Ð.r   c                ó6   • U R                  5       R                  $ )z5'*' or '_' for emphasis, fence string for fence, etc.)rœ   Úmarkupr5   s    r   r³   ÚSyntaxTreeNode.markup5  s   € ð ×$Ñ$Ó&×-Ñ-Ð-r   c                ó6   • U R                  5       R                  $ )zfence infostring)rœ   Úinfor5   s    r   r¶   ÚSyntaxTreeNode.info:  ó   € ð ×$Ñ$Ó&×+Ñ+Ð+r   c                ó6   • U R                  5       R                  $ )z/A place for plugins to store an arbitrary data.)rœ   Úmetar5   s    r   rº   ÚSyntaxTreeNode.meta?  r¸   r   c                ó6   • U R                  5       R                  $ )z5True for block-level tokens, false for inline tokens.)rœ   Úblockr5   s    r   r½   ÚSyntaxTreeNode.blockD  r£   r   c                ó6   • U R                  5       R                  $ )zZIf it's true, ignore this element when rendering.
Used for tight lists to hide paragraphs.)rœ   Úhiddenr5   s    r   rÀ   ÚSyntaxTreeNode.hiddenI  s   € ð ×$Ñ$Ó&×-Ñ-Ð-r   )r&   r%   r$   r#   N)r   )r-   úSequence[Token]r    r]   rJ   rK   )rJ   Ústr)r,   r   r;   ÚintrJ   r   )r,   r   r;   ÚslicerJ   úlist[_NodeType])r,   r   r;   zint | slicerJ   z_NodeType | list[_NodeType])r,   r   rJ   rI   )r,   r   rJ   rÆ   )r,   r   rS   rÆ   rJ   rK   )r,   r   rJ   ú_NodeType | None)r,   r   rS   rÇ   rJ   rK   )rJ   r]   )r,   r   rJ   zSequence[_NodeType])r-   rÂ   rJ   rK   )r|   rÄ   r}   r]   r~   rÄ   rJ   rÃ   )r,   r   r–   r]   rJ   z Generator[_NodeType, None, None])rJ   r   )rJ   zdict[str, str | int | float])r¦   rÃ   rJ   zNone | str | int | float)rJ   ztuple[int, int] | None)rJ   rÄ   )rJ   zdict[Any, Any])%r   r   r   r   Ú__doc__r/   r6   r	   r<   rL   Úpropertyr+   ÚsetterrV   rZ   r^   ra   r4   rk   rn   rq   r'   r’   r˜   rœ   rŸ   r�   r¥   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   