
    AHj2              	       P    d dl mZ d dlmZ d dlmZ d dlmZ 	 ddedededd	fd
Z	y	)    )
MarkdownIt)
StateBlock)StateInline)is_code_blockmdstart_delimiterend_delimiterreturnNc           
          dt         dt        dt        ffd}dt        dt        dt        dt        dt        f
fd}| j                  j
                  j                  dd	|       | j                  j
                  j                  d
d|       y)zA plugin to create substitution tokens.

    These, token should be handled by the renderer.

    Example::

        {{ block }}

        a {{ inline }} b

    statesilentr
   c                    	 | j                   | j                     k7  s| j                   | j                  dz      k7  ry	 | j                  dz   }d}	 	 | j                   j                  |      }	 | j                   |dz      k(  rd}n	 |dz   }=|sy| j                   | j                  dz   | j                         }|dz   | _        |ry| j                  ddd      }d|_        ||_        |j                  dd	       |j                  d
|         |_
        y# t        $ r Y yw xY w# t        $ r Y yw xY w# t        $ r Y yw xY w)N   F   Tsubstitution_inlinespanr   classsubstitutiontext)srcpos
IndexErrorindex
ValueErrorstrippushblockcontentattrSetmarkup)	r   r   r   found_closingendr   tokenr	   r   s	          T/root/tools/cai/cai_env/lib/python3.12/site-packages/mdit_py_plugins/substitution.py_substitution_inlinez1substitution_plugin.<locals>._substitution_inline   sk   			%))$799UYY]+> ? ii!miioomS999S1W%6$(M 7
 'C  yyQ-335!G	

0&!<g~.fd#)*=/:E  		    s5   ;D D) 0D8 	D&%D&)	D54D58	EE	startLineendLinec                 L   t        | |      ry| j                  |   | j                  |   z   }| j                  |   }| j                  || j                         }	 |d   
k7  s&|d   
k7  s|d   	k7  s|d   	k7  st        |      dk  ry	 |dd j                         }	dz  |v ry|dz   | _        |ry| j                  d	d
d      }d|_
        ||_        |j                  dd       |j                  d|       
 	 |_        || j                  g|_        y# t        $ r Y yw xY w)NFr   r      r   Tsubstitution_blockdivr   r   r   )r   bMarkstShifteMarksr   r   lenr   liner   r   r   r   r    map)r   r&   r'   r   startPosr"   lineTextr   r#   r	   r   s            r$   _substitution_blockz0substitution_plugin.<locals>._substitution_blockB   sL    	*<<	*U\\)-DDll9%99Xc*002
	.A;/1B<=0B<=0x=1$ % "~##% A$&]


/:g~.fd#)*=/:

+	-  		s   .D 	D#"D#fencer,   escaper   N)r   boolr   intr   rulerbeforeinline)r   r   r	   r%   r6   s    ``  r$   substitution_pluginr>      s    )K ) )$ )V**&)*47*AE*	*X HHNN'#79LMIIOO8%:<PQ    ){})
markdown_itr   markdown_it.rules_blockr   markdown_it.rules_inliner   mdit_py_plugins.utilsr   strr>    r?   r$   <module>rH      sG    " . 0 / FIgRgR%(gR?BgR	gRr?   