ó
    Ð~,h�,  ã                  ó’   • 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SS j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   ó    Ú2/usr/lib/python3/dist-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__M   s$   € Ü�t“*×%Ñ%Ð& a¨¯	©	 {°!Ð4Ð4r   c                ó   • g ©Nr   ©r,   Úitems     r   Ú__getitem__ÚSyntaxTreeNode.__getitem__P   ó   € àr   c                ó   • g r9   r   r:   s     r   r<   r=   T   r>   r   c                ó    • U R                   U   $ r9   )r+   r:   s     r   r<   r=   X   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   rH   Ú:SyntaxTreeNode.to_tokens.<locals>.recursive_collect_tokens^   s—   ø€ Ø�y‰y˜FÓ"Ø!Ÿ]œ]�EÙ,¨UÖ?ò +à——Ø×!Ñ! $§*¡*Õ-à×)×)Ð)Ð)Ø×!Ñ! $×"4Ñ"4×"<Ñ"<Ô=Ø!Ÿ]œ]�EÙ,¨UÖ?ñ +à×!Ñ! $×"4Ñ"4×"<Ñ"<Õ=r   )rE   r   rF   úlist[Token]ÚreturnÚNoner   )r,   r-   rH   s     @r   Ú	to_tokensÚSyntaxTreeNode.to_tokens[   s   ø€ ÷	>ð !ˆÙ  Ô.Øˆr   c                ó   • U R                   $ r9   ©r&   r5   s    r   r+   ÚSyntaxTreeNode.childreno   s   € à�~‰~Ðr   c                ó   • Xl         g r9   rP   ©r,   Úvalues     r   r+   rQ   s   s   € à�r   c                ó   • U R                   $ r9   ©r%   r5   s    r   ÚparentÚSyntaxTreeNode.parentw   s   € à�|‰|Ðr   c                ó   • Xl         g r9   rV   rS   s     r   rW   rX   {   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.
)rW   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                  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
rC   Ú_open)r[   r#   r4   r$   Ú_removesuffixr   r5   s    r   r4   ÚSyntaxTreeNode.type˜   sQ   € ð �<�<ØØ�:�:Ø—:‘:—?‘?Ð"Ø×!×!Ð!Ð!Ü˜T×/Ñ/×7Ñ7×<Ñ<¸gÓFÐFr   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)rb   Ú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)rb   ri   rj   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   rW   r+   rD   )r,   r-   rG   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*   rr   r(   rD   )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   r[   ÚattrsÚjoinÚitemsÚcontentÚtextwrapr}   r+   Úpretty)r,   r}   r~   r   Úprefixr‹   rG   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—   rG   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.content0  s   € ð ×$Ñ$Ó&×.Ñ.Ð.r   c                ó6   • U R                  5       R                  $ )z5'*' or '_' for emphasis, fence string for fence, etc.)r�   Úmarkupr5   s    r   r´   ÚSyntaxTreeNode.markup6  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.blockE  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.hiddenJ  s   € ð ×$Ñ$Ó&×-Ñ-Ð-r   )r&   r%   r$   r#   N)r   )r-   úSequence[Token]r    r^   rK   rL   )rK   Ústr)r,   r   r;   ÚintrK   r   )r,   r   r;   ÚslicerK   úlist[_NodeType])r,   r   r;   zint | slicerK   z_NodeType | list[_NodeType])r,   r   rK   rJ   )r,   r   rK   rÇ   )r,   r   rT   rÇ   rK   rL   )r,   r   rK   ú_NodeType | None)r,   r   rT   rÈ   rK   rL   )rK   r^   )r,   r   rK   zSequence[_NodeType])r-   rÃ   rK   rL   )r}   rÅ   r~   r^   r   rÅ   rK   rÄ   )r,   r   r—   r^   rK   z Generator[_NodeType, None, None])rK   r   )rK   zdict[str, str | int | float])r§   rÄ   rK   zNone | str | int | float)rK   ztuple[int, int] | None)rK   rÅ   )rK   zdict[Any, Any])%r   r   r   r   Ú__doc__r/   r6   r	   r<   rM   Úpropertyr+   ÚsetterrW   r[   r_   rb   r4   rl   ro   rr   r'   r“   r™   r�   r    rŽ   r¦   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                ó^   • U(       a%  U R                  U5      (       a  U S[        U5      *  $ U $ )zuRemove a suffix from a string.

Replace this with str.removesuffix() from stdlib when minimum Python
version is 3.9.
N)Úendswithr)   )ÚstringÚsuffixs     r   rf   rf   Q  s-   € ö �&—/‘/ &×)Ñ)Ø�nœ˜V›˜Ð%Ð%Ø€Mr   )rÎ   rÄ   rÏ   rÄ   rK   rÄ   )rÉ   Ú
__future__r   Úcollections.abcr   r   r’   Útypingr   r   r   r	   r#   r   r   r   r   rf   r   r   r   Ú<module>rÓ      sK   ðñõ #ç /Û ß 5Ó 5å ô�Jô ñ
 �KÐ'7Ñ8€	÷x.ñ x.õv	r   