
    ei9                         d Z ddlmc mZ ddlmZmZ ddlmZ ddl	m
Z
 ddlZ ej                  d      Z ej                  d	      Zd
 Z G d de
      Z G d de      Z G d de      Zd Zy)a  
Captions.

Captions should be placed after a block, that block will be wrapped in a `figure`
and captions will be inserted either at the end of the figure or at the beginning.
If the preceding block happens to be a `figure`, if no `figcaption` is detected
within, the caption will be injected into that figure instead of wrapping.
Keep in mind that when `md_in_html` is used and raw HTML is used, if `markdown=1`
is not present on the caption, the caption will be invisible to this extension.

Class, IDs, or other attributes will be attached to the figure, not the caption.

`types`:
    A dictionary with figure type names and prefix templates. A template will be
    used depending on whether the current type is assumed or directly specified.
`prepend`:
    Will prepend `figcaption` at the start of a `figure` instead of the end.
`auto`:
    Will generate IDs and prefixes via the provided template for all figures of
    a given type as long as they also define a prefix template.
`auto_level`:
    Auto number will not be shown below the given level depth. A value of 0, the
    default, disables the feature, 1 would show only auto-generate IDs and
    prefixes for the outermost figures with prefixes, etc. This level is only
    considered for each figure type individually.

    N   )Blocktype_html_identifier   )BlocksExtension)Treeprocessorz,^(\^)?([1-9][0-9]*(?:\.[1-9][0-9]*)*)(?= |$)z[_-]+c                 J   d| j                   vr;d| ddj                  d |j                  d      D              z   | j                   d<   |rW|rt        |       n
t	        |       D ]:  }|j
                  dk(  st        |      }|j                  j                  |j                  |            }t        |      r|d   j
                  dk7  r`t        j                  d      }	t        j                  |	d	d
di      }
||
_        |j                  |	_        d|_        |j                  d|	       |d   }	t        j                  d	d
di      }
||
_        t!        |	j                         }|sd|	j                  z   n|	j                  |
_        d|	_        |	j                  d|
       = yy)z!Update tag ID and caption prefix.id___c              3   2   K   | ]  }t        |        y wNstr.0xs     Y/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/pymdownx/blocks/caption.py	<genexpr>zupdate_tag.<locals>.<genexpr>+   s     5Yc!f5Y   .
figcaptionr   pspanclasszcaption-prefixN )attribjoinsplitlistreversedtag	htmlStashstoreformatlenetreeElement
SubElementtexttailinsertbool)elfig_typefig_numtemplateprependmdchildchildrenvaluer   r   emptys               r   
update_tagr8   &   sb    299xj*SXX5YgmmTWFX5Y-YY		$ !(T"Xhrl 	&EyyL(;**8??7+CD8}3(>c*A ++AvAQ7RSD %DI"ZZAF!%EJLLA& A ==';K1LMD %DI $QVV,E6;qvvDI!AFHHQ%%	&     c                   (     e Zd ZdZ fdZd Z xZS )CaptionTreeprocessorzCaption tree processor.c                     t         |   |       |d   | _        |d   | _        d| _        t        d|d         | _        || _        y)Initialize.autor2    r   
auto_levelN)super__init__r>   r2   typemaxr@   	fig_types)selfr3   typesconfig	__class__s       r   rB   zCaptionTreeprocessor.__init__G   sJ     	6N	i(	a!56r9   c                    |j                         D ci c]  }|D ]  }||  }}}t        j                  | j                  d      }| j                  D ci c]  }|dg }}| j                  x}}	g }
d}|j                         D ]  }d}d}|j
                  dk(  rl|	}d}d}d|j                  v rd}|j                  d= d|j                  v r>|j                  d   }|
j                  |       || j                  vs| j                  |   sd	|j                  v r:|t        |j                  d	         d
z   z  }| j                  r|| j                  k\  r|d
z  }|}	 |j                  |d      }|n|j
                  dk(  r|j                  d   |k(  rod	|j                  v }|r|t        |j                  d	         d
z   z  }n|d
z  }|rt        |d
z         |j                  d	<   | j                  r|| j                  k\  rd}n|}|r|dkD  sd|j                  v rc|j                  d   j                  d      D cg c]  }t        |       }}|j                  d= t        |      d
z
  }||z
  |j                  d	<   |}||   }||   }||kD  r|j                  d
g||z
  z         n(||k(  r||xx   d
z  cc<   n||d
z   d= |dxx   d
z  cc<   |||<   |}	|r||kD  r|dd |dd t        ||dj!                  d |d|d
z    D              | j                  j                  |d      | j"                          |
D ]+  }|j                  d= d	|j                  v s|j                  d	= - yc c}}w c c}w c c}w )z Update caption IDs and prefixes.r   r?   figureF__figure_prependT__figure_type__figure_levelr   N__figure_numr   c              3   2   K   | ]  }t        |        y wr   r   r   s     r   r   z+CaptionTreeprocessor.run.<locals>.<genexpr>   s     ASVAr   )iterdictfromkeysrE   rC   r"   r   appendintr@   getr   r   r&   extendr8   r   r3   )rF   docr   c
parent_maplastkcountersr/   	last_typefigsr0   r.   stackr2   skipcurrentparentlevelr   	new_stacklcounterfigs                           r   runzCaptionTreeprocessor.runR   s    %(HHJ:q:1ad:a:
:}}T^^Q/$(NN3qAsF33#yy(9 ((* `	BGEvv!$ &2"G		"45 #bii/!yy9HKKOt~~5T^^H=U   $ryy0S+;!<=AAE5DOO+C QJE'^^GT:F ~ zzX-&--2PT\2\ 0FMM A !S7G)H%IA%MME!QJE :=eai.BII&67??u/G#'D!$G- 0  rz!RYY./1yy/H/N/Ns/ST!s1vTGT		.1 #Gq 0I2;e2CBII./%E N"8,19NNA3%!)#45aZENa'N	
+BK1$K!&X$	 w0!(GAJ HHAWZeai-@AANN&&x4GGs`	F  	1C

?+3::-JJ/0	1W ;3N Us   M+M1>M6)__name__
__module____qualname____doc__rB   rj   __classcell__rI   s   @r   r;   r;   D   s    !	q1r9   r;   c                   J    e Zd ZdZdZdZdZdZddefiZ	d Z
d Zd Zd Zd	 Zy)
CaptionzFigure captions.r?   NrC   c                     | j                   d   | _        | j                   d   | _        d| _        d| _        d| _        | j                  j                         | _        y)r=   r>   r2   Nr?   )	rH   r>   r2   captionr0   re   CLASSESr   classes)rF   s    r   on_initzCaption.on_init   sM     KK'	{{9-
||))+r9   c                    | j                   }|rG|j                  d      rd| _        |dd j                         }n+|j                  d      rd| _        |dd j                         }t        j                  |      }|r_|j                  d      r|j                  d      | _        n|j                  d      | _        ||j                         d j                         }|rx|j                         }t        |      dkD  ry|d   }|j                  d	      sy|dd }	 t        |      }t        | j                  d
         }d|vr||d<   || j                  d
<   yy# t        $ r Y yw xY w)zHandle on validate event.>Fr   N<Tr   r   #attrsr
   )argument
startswithr2   lstrip
RE_FIG_NUMmatchgroupre   r0   endr   r&   r   
ValueErrorrS   options)rF   rd   r}   mtokensid_token
identifierr|   s           r   on_validatezCaption.on_validate   sX    ==""3'$#AB<..0$$S)##AB<..0  *A771:!"DJ#$771:DL#AEEGH-446!)v;? !!9**3/ %ab\
!!5j!AJ T\\'23u$",E$K,1DLL) " ! !s   E 	E$#E$c                 `   d}d}t        |      }|r9|d   }|j                  dk(  r%|}t        |      D ]  }|j                  dk(  sd} n |g| j                  si nddj                  | j                        i}t	        j
                  |d|      }||j                  |       |j                  |       n| j                  r|j                  j                  dd      j                         }|r/|j                         }| j                  D ]  }||vs|d|z   z  } ndj                  | j                        }||j                  d<   | j                  rc| j                  |j                  d<   | j                  r| j                  |j                  d	<   | j                   r| j                   |j                  d
<   | j"                  rS| j                  rd|j                  d<   t	        j$                  d      | _        |j)                  d| j&                         |S t	        j
                  |d      | _        |S )zCreate the element.NrK   rL   r   r   r   r?   rN   rO   rP   1rM   r   )r    r"   rv   r   r'   r)   rU   removeru   r   rW   stripr   r>   NAMEre   r0   r2   r(   rt   r,   )	rF   rd   ri   r4   r5   rZ   r   rv   
class_lists	            r   	on_createzCaption.on_create  s    <RLEyyH$e Auu," ;#||R'388DLL;Q1RF""68V<C 

5!e$ \\jjnnWb1779G$]]_
 +A
*37*+ ((4<<0")CJJw99*.))CJJ'zz/3zz

+,||-1\\

>* <<yy14

-. ==6DLJJq$,,' 
 !++C>DL
r9   c                     | j                   S )z3Return caption as the target container for content.)rt   )rF   blocks     r   on_addzCaption.on_add;  s     ||r9   c                 >   | j                   }|r| j                  s| j                  r0dj                  dgt	        | j                        dz   z        | _        | j
                  r9t        || j                  | j
                  || j                  | j                         yyyy)z.Handle explicit, manual prefixes on block end.r   r   r   N)
PREFIXr>   re   r   rV   r0   r8   r   r2   r3   )rF   r   prefixs      r   on_endzCaption.on_end@  s~     $))zz"xxTZZ11D(EF||IILLLLGG 	 $6r9   )rk   rl   rm   rn   r   r   ru   ARGUMENTr   OPTIONSrw   r   r   r   r    r9   r   rr   rr      sF    DFGH)*G,&P6p
r9   rr   c                   (     e Zd ZdZ fdZd Z xZS )CaptionExtensionzCaption Extension.c                 ^    dddddddgdgdd	gd
dgddgd| _         t        |   |i | y)r=   rt   zfigure-captionz
Figure {}.)namer   ztable-captionz	Table {}.zConfigure types a list of types, each type is a dictionary that defines a 'name' and 'prefix' A template must contain '{}' for numerical insertions unless the template is an empty string which will assume no prefix should be used.r   z1Depth of children to add prefixes to - Default: 0TzcAuto add IDs with prefixes (prefixes are only added if prefix template is defined) - Default: FalseFz6Prepend captions opposed to appending - Default: False)rG   r@   r>   r2   N)rH   rA   rB   )rF   argskwargsrI   s      r   rB   zCaptionExtension.__init__V  ss      0".
 !0"-
>" C
 u
 H3
> 	$)&)r9   c                    | j                         }i }|d   D ]  }t        |t              r*|d   }|j                  dd      }|j                  dd      }n|}d}d}|||<   t        j                  d|      j                         }	|j                  t        |	t        fi |||d      |d   |d   |d	   d
        |d   r)|j                  j                  t        |||      dd       yy)zExtend Markdown blocks.rG   r   r   r?   rv   )r   r   r   ru   r@   r>   r2   )r@   r>   r2   zcaption-auto   N)
getConfigs
isinstancerS   rW   RE_SEPsubtitleregisterrC   rr   treeprocessorsr;   )
rF   r3   	block_mgrrH   rG   objr   r   rv   subclasss
             r   extendMarkdownBlocksz%CaptionExtension.extendMarkdownBlocksz  s    " '? 	C#t$6{2.'')R0 E$Kzz"d+113HJ#% $"(#*		  &l3VF^X^_hXij	2 &>&&';Bv'NP^`ab r9   )rk   rl   rm   rn   rB   r   ro   rp   s   @r   r   r   S  s    "*H!cr9   r   c                      t        | i |S )zReturn extension.)r   )r   r   s     r   makeExtensionr     s     T,V,,r9   )rn   xml.etree.ElementTreer'   ElementTreer   r   r   blocksr   markdown.treeprocessorsr   recompiler   r   r8   r;   rr   r   r   r   r9   r   <module>r      sx   6 & % . % 1 	RZZGH
	H	&<1= 1DJe JZHc HcV-r9   