
    f                         d dl Z d dlmZmZ  e j                  d      Z G d d      Z G d d      Z G d d	      Z G d
 de	      Z
y)    N)DictAnyz\n|$c                       e Zd ZdZddZdefdZdefdZd Zde	fd	Z
d
 Zdeeef   fdZdeeef   fdZdefdZd Zd Zy)
BlockStatez3The state to save block parser's cursor and tokens.Nc                     d| _         g | _        d| _        d| _        d| _        || _        |r|j                  | _        y di i| _        y )N r   T	ref_links)srctokenscursor
cursor_max
list_tightparentenv)selfr   s     G/var/www/cvtools/html/venv/lib/python3.12/site-packages/mistune/core.py__init__zBlockState.__init__	   sL       zzDH#R(DH    r
   c                 J    | j                  |       }|j                  |       |S N)	__class__process)r   r
   childs      r   child_statezBlockState.child_state   s!    t$cr   c                 2    || _         t        |      | _        y r   )r
   lenr   )r   r
   s     r   r   zBlockState.process    s    c(r   c                 v    t         j                  | j                  | j                        }|j	                         S r   )	_LINE_ENDsearchr
   r   end)r   ms     r   find_line_endzBlockState.find_line_end$   s'    TXXt{{3uuwr   end_posc                 4    | j                   | j                  | S r   )r
   r   )r   r#   s     r   get_textzBlockState.get_text(   s    xxG,,r   c                 :    | j                   r| j                   d   S y )N)r   r   s    r   
last_tokenzBlockState.last_token+   s    ;;;;r?" r   tokenc                 h    | j                   j                  t        | j                         dz
  |       yz#Insert token before the last token.   Nr   insertr   r   r*   s     r   prepend_tokenzBlockState.prepend_token/   $    3t{{+a/7r   c                 :    | j                   j                  |       yz#Add token to the end of token list.Nr   appendr0   s     r   append_tokenzBlockState.append_token3       5!r   textc                     | j                         }|r|d   dk(  r|dxx   |z  cc<   y | j                  j                  d|d       y )Ntype	paragraphr9   )r;   r9   )r)   r   r6   )r   r9   r)   s      r   add_paragraphzBlockState.add_paragraph7   sD    __&
*V,;v$&KKTBCr   c                     | j                         }|r7|d   dk(  r.| j                         }|dxx   | j                  |      z  cc<   |S y y )Nr;   r<   r9   )r)   r"   r%   )r   r)   poss      r   append_paragraphzBlockState.append_paragraph>   sP    __&
*V,;$$&Cv$--"44J <:r   c                 N    d}| j                   }|r|dz  }|j                   }|r|S )Nr   r-   )r   )r   dr   s      r   depthzBlockState.depthE   s1    FA]]F  r   r   )__name__
__module____qualname____doc__r   strr   r   r"   intr%   r)   r   r   r1   r7   r=   r@   rC    r   r   r   r      sx    =)$s 
#3 #- -#84S> 8"$sCx. "D# Dr   r   c                   X    e Zd ZdZdeeef   fdZdeeef   fdZdeeef   fdZ	d Z
y)	InlineStatez)The state to save inline parser's tokens.r   c                 f    || _         d| _        g | _        d| _        d| _        d| _        d| _        y )Nr   F)r   r
   r   in_imagein_linkin_emphasis	in_strong)r   r   s     r   r   zInlineState.__init__P   s4     r   r*   c                 h    | j                   j                  t        | j                         dz
  |       yr,   r.   r0   s     r   r1   zInlineState.prepend_tokenY   r2   r   c                 :    | j                   j                  |       yr4   r5   r0   s     r   r7   zInlineState.append_token]   r8   r   c                     | j                  | j                        }| j                  |_        | j                  |_        | j                  |_        | j
                  |_        |S )zCreate a copy of current state.)r   r   rN   rO   rP   rQ   )r   states     r   copyzInlineState.copya   sH    txx( ,,..r   N)rD   rE   rF   rG   r   rH   r   r   r1   r7   rV   rJ   r   r   rL   rL   N   sF    3DcN 84S> 8"$sCx. "r   rL   c                   j    e Zd Zej                  ZeZi Zg Z	d Z
d	dZd	defdZd Zed	d       Zd Zy)
Parserc                     | j                   j                         | _        t        | j                        | _        i | _        i | _        y r   )SPECIFICATIONrV   specificationlistDEFAULT_RULESrules_methods_Parser__scr(   s    r   r   zParser.__init__r   s9    !//446$,,-
	r   Nc                     |d} j                   }ndj                  |      } j                  j                  |      }|r|S dj                   fd|D              }t	        j
                  | j                        }| j                  |<   |S )N$|c              3   J   K   | ]  }d |dj                   |   d  yw)z(?P<>)N)r[   ).0kr   s     r   	<genexpr>z$Parser.compile_sc.<locals>.<genexpr>   s!     S!T-?-?-BCSs    #)r^   joinr`   getrecompilesc_flag)r   r^   keyscregexs   `    r   
compile_sczParser.compile_scy   sw    =CJJE((5/CYY]]3ISUSSZZt||,		#	r   namec                       fd j                   |<   |r| j                  |<   | j                  vr j                   j                  ||       yy)a3  Register a new rule to parse the token. This method is usually used to
        create a new plugin.

        :param name: name of the new grammar
        :param pattern: regex pattern in string
        :param func: the parsing function
        :param before: insert this rule before a built-in rule
        c                      | |      S r   rJ   )r!   rU   funcr   s     r   <lambda>z!Parser.register.<locals>.<lambda>   s    tD!U/C r   )beforeN)r_   r[   r^   insert_rule)r   rs   patternrv   rx   s   `  ` r   registerzParser.register   sQ     Dd'.Dt$tzz!TZZf= "r   c                     t        d      )Nz.This plugin is not compatible with mistune v3.)DeprecationWarning)r   rs   rz   rv   s       r   register_rulezParser.register_rule   s     !QRRr   c                     |r%	 | j                  |      }| j                  ||       y | j                  |       y # t        $ r | j                  |       Y y w xY wr   )indexr/   
ValueErrorr6   )r^   rs   rx   r   s       r   ry   zParser.insert_rule   sQ    #F+UD) LL  #T"#s   #: AAc                 F    | j                   |j                     } |||      S r   )r_   	lastgroup)r   r!   rU   rv   s       r   parse_methodzParser.parse_method   s     }}Q[[)Au~r   r   )rD   rE   rF   rl   Mrn   r   	state_clsrZ   r]   r   rr   rH   r{   r~   staticmethodry   r   rJ   r   r   rX   rX   k   sO    ddGIMM >S >S  r   rX   c                   @    e Zd ZdZd ZdefdZd Zd Zd Z	d Z
d	 Zy
)BaseRendererbasec                     i | _         y r   _BaseRenderer__methodsr(   s    r   r   zBaseRenderer.__init__   s	    r   rs   c                 .      fd j                   |<   y)zRegister a render method for the named token. For example::

            def render_wiki(renderer, key, title):
                return f'<a href="/wiki/{key}">{title}</a>'

            renderer.register('wiki', render_wiki)
        c                       g| i |S r   rJ   )argkwargsmethodr   s     r   rw   z'BaseRenderer.register.<locals>.<lambda>   s    fT6RC6R66R r   Nr   r   rs   r   s   ` `r   r{   zBaseRenderer.register   s      Str   c                     	 t         j                  | |      S # t        $ r< | j                  j	                  |      }|st        dj                  |            |cY S w xY w)NzNo renderer "{!r}")object__getattribute__AttributeErrorr   rk   formatr   s      r   _get_methodzBaseRenderer._get_method   s\    	**466 	^^''-F$%9%@%@%FGGM		s    AAAc                 <    | j                  |d         } |||      S )Nr;   )r   )r   r*   rU   rv   s       r   render_tokenzBaseRenderer.render_token   s#    f.E5!!r   c              #   B   K   |D ]  }| j                  ||        y wr   )r   )r   r   rU   toks       r   iter_tokenszBaseRenderer.iter_tokens   s(      	0C##C//	0s   c                 D    dj                  | j                  ||            S )Nr   )rj   r   r   r   rU   s      r   render_tokenszBaseRenderer.render_tokens   s    wwt''677r   c                 &    | j                  ||      S r   )r   r   s      r   __call__zBaseRenderer.__call__   s    !!&%00r   N)rD   rE   rF   NAMEr   rH   r{   r   r   r   r   r   rJ   r   r   r   r      s3    D	SS 	S"081r   r   )rl   typingr   r   rm   r   r   rL   rX   r   r   rJ   r   r   <module>r      sI    	 BJJw	D DN := =@&16 &1r   