
    ͆hK7                         S r SSKJs  Jr  SSKJrJr  SSKJr  SSK	J
r
  SSKr\R                  " S5      r\R                  " S	5      rS
 r " S S\
5      r " S S\5      r " S S\5      rS rg)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                    SU R                   ;  a;  SU S3SR                  S UR                  S5       5       5      -   U R                   S'   U(       Gaq  U(       a  [        U 5      O
[	        U 5       GHN  nUR
                  S:X  d  M  [        U5      nUR                  R                  UR                  U5      5      n[        U5      (       a  US   R
                  S:w  ab  [        R                  " S5      n	[        R                  " U	S	S
S05      n
Xl        UR                  U	l        SUl        UR                  SU	5        M  US   n	[        R                  " S	S
S05      n
Xl        [!        U	R                  5      (       + nU(       d  SU	R                  -   OU	R                  U
l        SU	l        U	R                  SU
5        GMQ     gg)z!Update tag ID and caption prefix.id___c              3   8   #    U  H  n[        U5      v   M     g 7fNstr.0xs     O/opt/services/DDDS/venv/lib/python3.13/site-packages/pymdownx/blocks/caption.py	<genexpr>update_tag.<locals>.<genexpr>+   s     5YFXc!ffFX   .
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_tagr9   &   s^    299xj*SXX5YgmmTWFX5Y-YY		$ !(T"Xhrl:EyyL(;**8??7+CD8}}3(>c*A ++AvAQ7RSD %I"ZZAF!%EJLLA& A ==';K1LMD %I $QVV,E6;qvvDI!AFHHQ%% ;     c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )CaptionTreeprocessorD   zCaption tree processor.c                    > [         TU ]  U5        US   U l        US   U l        SU l        [        SUS   5      U l        X l        g)Initialize.autor3    r   
auto_levelN)super__init__r@   r3   typemaxrB   	fig_types)selfr4   typesconfig	__class__s       r   rD   CaptionTreeprocessor.__init__G   sH     	6N	i(	a!56r:   c                    UR                  5        VVs0 s H  o"  H  o3U_M     M     nnn[        R                  U R                  S5      nU R                   Vs0 s H  ofS/_M     nnU R                  =p/ n
SnUR                  5        GH  nSnSnUR
                  S:X  Ga  U	nSnSnSUR                  ;   a  SnUR                  S	 SUR                  ;   aF  UR                  S   nU
R                  U5        XR                  ;  d  U R                  U   (       d  M  OM  S	UR                  ;   aA  U[        UR                  S	   5      S
-   -  nU R                  (       a  XR                  :  a  M  OUS
-  nUn UR                  US5      nUc  OUR
                  S:X  a  UR                  S   U:X  a  S	UR                  ;   nU(       a  U[        UR                  S	   5      S
-   -  nOUS
-  nU(       a  [        US
-   5      UR                  S	'   U R                  (       a  XR                  :  a  SnOUnM  U(       a  GM  US:  d  GM  SUR                  ;   af  UR                  S   R                  S5       Vs/ s H  n[        U5      PM     nnUR                  S	 [        U5      S
-
  nUU-
  UR                  S	'   UnXX   nXx   nUU:  a  UR                  S
/UU-
  -  5        O)UU:X  a  UU==   S
-  ss'   OUUS
-   S2	 US==   S
-  ss'   XU'   Un	U(       a  UU:  a  USS USS& [        UUSR!                  S USUS
-     5       5      U R                  R                  US5      WU R"                  5        GM     U
 H/  nUR                  S	 S	UR                  ;   d  M"  UR                  S		 M1     gs  snnf s  snf s  snf )z Update caption IDs and prefixes.r   rA   figureF__figure_prependT__figure_type__figure_levelr   N__figure_numr   c              3   8   #    U  H  n[        U5      v   M     g 7fr   r   r   s     r   r   +CaptionTreeprocessor.run.<locals>.<genexpr>   s     A-@SVV-@r   )iterdictfromkeysrG   rE   r#   r   appendintrB   getr   r    r'   extendr9   r   r4   )rH   docr   c
parent_maplastkcountersr0   	last_typefigsr1   r/   stackr3   skipcurrentparentlevelr   	new_stacklcounterfigs                           r   runCaptionTreeprocessor.runR   s    %(HHJ:Jq1daJ
:}}T^^Q/$(NN3NqsFN3#yy( ((*BGEvv!$ &2"G		"45 #bii/!yy9HKKO~~5T^^H=U  >V  $ryy0S+;!<=AAE5OO+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/S!s1v/SGT		.1 #Gq 0I2;e2CBII./%E N",19NNA3%!)#45aZENa'N	
+BK1$K!&X$	 w0!(GAJ HHAWZeai-@AANN&&x4GGs F C

?+3::-JJ/0 W ;3N Us   N4N:8N?)r@   rB   rG   r3   rE   )	__name__
__module____qualname____firstlineno____doc__rD   rn   __static_attributes____classcell__rK   s   @r   r<   r<   D   s    !	q1 q1r:   r<   c                   R    \ rS rSrSrSrSrSrSrSS\	40r
S rS rS rS	 rS
 rSrg)Caption   zFigure captions.rA   NrE   c                     U R                   S   U l        U R                   S   U l        SU l        SU l        SU l        U R                  R                  5       U l        g)r?   r@   r3   NrA   )	rJ   r@   r3   captionr1   ri   CLASSESr    classes)rH   s    r   on_initCaption.on_init   sM     KK'	{{9-
||))+r:   c                    U R                   nU(       a  UR                  S5      (       a  SU l        USS R                  5       nO0UR                  S5      (       a  SU l        USS R                  5       n[        R                  U5      nU(       ac  UR                  S5      (       a  UR                  S5      U l        OUR                  S5      U l        X#R                  5       S R                  5       nU(       a  gg)zHandle on validate event.>Fr   N<Tr   )
argument
startswithr3   lstrip
RE_FIG_NUMmatchgroupri   r1   end)rH   rh   r   ms       r   on_validateCaption.on_validate   s     ==""3''$#AB<..0$$S))##AB<..0  *A771::!"DJ#$771:DL#EEGH-446r:   c                    SnSn[        U5      nU(       a=  US   nUR                  S:X  a(  Un[        U5       H  nUR                  S:X  d  M  Sn  O   Ucn  U R                  (       d  0 OSSR                  U R                  5      0n[        R
                  " USU5      nUb"  UR                  U5        UR                  U5        OU R                  (       a  UR                  R                  SS5      R                  5       nU(       a3  UR                  5       nU R                   H  nXX;  d  M
  USU-   -  nM     OSR                  U R                  5      nXrR                  S'   U R                  (       am  U R                  UR                  S'   U R                  (       a  U R                  UR                  S	'   U R                   (       a  U R                   UR                  S
'   U R"                  (       aY  U R                  (       a  SUR                  S'   [        R$                  " S5      U l        UR)                  SU R&                  5        U$ [        R
                  " US5      U l        U$ )zCreate the element.NrN   rO   r   r   r   rA   rQ   rR   rS   1rP   r   )r!   r#   r~   r   r(   r*   rY   remover}   r   r[   stripr    r@   NAMEri   r1   r3   r)   r|   r-   )	rH   rh   rm   r5   r6   r^   r   r~   
class_lists	            r   	on_create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")JJw99*.))CJJ'zz/3zz

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

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

-. ==6DLJJq$,,' 
 !++C>DL
r:   c                     U R                   $ )z3Return caption as the target container for content.)r|   )rH   blocks     r   on_addCaption.on_add+  s     ||r:   c                 f   U R                   nU(       a  U R                  (       d  U R                  (       a0  SR                  S/[	        U R                  5      S-   -  5      U l        U R
                  (       a9  [        UU R                  U R
                  UU R                  U R                  5        gggg)z.Handle explicit, manual prefixes on block end.r   r   r   N)
PREFIXr@   ri   r   rZ   r1   r9   r   r3   r4   )rH   r   prefixs      r   on_endCaption.on_end0  s~     $))zz"xxTZZ11D(EF||IILLLLGG 	 $6r:   )r@   r|   r~   r1   ri   r3   )rp   rq   rr   rs   rt   r   r   r}   ARGUMENTr   OPTIONSr   r   r   r   r   ru    r:   r   ry   ry      sE    DFGH)*G,06p
r:   ry   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )CaptionExtensioniC  zCaption Extension.c                 `   > SSSS.SSS./S/SS	/S
S/SS/S.U l         [        TU ]  " U0 UD6  g)r?   r|   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)rI   rB   r@   r3   N)rJ   rC   rD   )rH   argskwargsrK   s      r   rD   CaptionExtension.__init__F  ss      0".
 !0"-
>" C
 u
 H3
> 	$)&)r:   c                    U R                  5       n0 nUS    H  n[        U[        5      (       a*  US   nUR                  SS5      nUR                  SS5      nOUnSnSnXtU'   [        R                  SU5      R                  5       n	UR                  [        U	[        40 UUUS.5      US   US   US	   S
.5        M     US   (       a(  UR                  R                  [        XU5      SS5        gg)zExtend Markdown blocks.rI   r   r   rA   r~   )r   r   r   r}   rB   r@   r3   )rB   r@   r3   zcaption-auto   N)
getConfigs
isinstancerW   r[   RE_SEPsubtitleregisterrE   ry   treeprocessorsr<   )
rH   r4   	block_mgrrJ   rI   objr   r   r~   subclasss
             r   extendMarkdownBlocks%CaptionExtension.extendMarkdownBlocksj  s    " '?C#t$$6{2.'')R0 $Kzz"d+113HJ#% $"(#*		  &l3VF^X^_hXij #2 &>&&';Bv'NP^`ab r:   )rJ   )	rp   rq   rr   rs   rt   rD   r   ru   rv   rw   s   @r   r   r   C  s    "*H!c !cr:   r   c                      [        U 0 UD6$ )zReturn extension.)r   )r   r   s     r   makeExtensionr     s     T,V,,r:   )rt   xml.etree.ElementTreer(   ElementTreer   r   r   blocksr   markdown.treeprocessorsr   recompiler   r   r9   r<   ry   r   r   r   r:   r   <module>r      st   6 & % . % 1 	ZZGH
	H	&<1= 1Dze zzHc HcV-r:   