
    )ig+                        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       P/var/www/html/land-doc-ocr/venv/lib/python3.13/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!!9L## Q  &J$$..|/D/DE % "/vay&*!ED**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    yyF"!]]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     JJ4$"4"455r   c                ,    [        U R                  5      $ )zIs 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"     {{6M{{###r   c                    U R                   (       a  gU R                  (       a  U R                  R                  $ U R                  (       d   eU R                  R                  R                  R                  S5      $ )zGet 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
6u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"GMG!g'++-$$U+==( "gg  #<]1=M<N!OPPOOM*% 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<NDAaS!<<Ns   >)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!DII;'||

C#(("ODJJ<L<L<N"OOOODLL		55D8??4<<#,9NOOOD]]ED5<<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)zRecursively 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zztz444 #4s   -;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   
 )+(9CG(9%(9<@(9	(9T5 A AI I#(   __    ]]  6 6 ( ( $ $ E E    $$ 
$+2  !E1-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   