
    $gP(                        d Z ddlmZmZ ddlZddlZddlZddlmZ	  ej
        dej        ej        z            Z ej
        d          Z ej
        d          ZddZd	 Zd
 Zd Zd Zd Zd Zd dZd dZd Z eee          Zd Zd Zd Zd Zd Zd!dZ efdZ!d Z" e!de          Z# G d de          Z$dS )"zBlock class.    )ABCMetaabstractmethodN)utilz
    (?:(?:-?(?:[^\x00-\x2f\x30-\x40\x5B-\x5E\x60\x7B-\x9f])+|--)
    (?:[^\x00-\x2c\x2e\x2f\x3A-\x40\x5B-\x5E\x60\x7B-\x9f])*)
    z(?m)^([ ]*)[^ \n]z(?m)^([ ]*)($)?c                     |D ]}	  ||           c S # t           $ r Y w xY wt          dt          |            d          )zMulti types.zType 'z)' did not match any of the provided types
ValueErrortype)valuetypests      U/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/blocks/block.py_type_multir      sk       	1U88OOO 	 	 	D	 Td5kkTTT
U
UUs   

  c                  8    t          j        t          |           S )z-Validate a type with multiple type functions.)r   )	functoolspartialr   )argss    r   
type_multir   !   s     [5555    c                     | S )zAccepts any type. r
   s    r   type_anyr   '   s	     Lr   c                 H    | t          t          |            d          dS )zEnsure type None or fail.Nz is not Noner   r   s    r   	type_noner   -   s/     DKK555666 r   c                      ||           } || |k     rt          |  d|           || |k    rt          |  d|           | S )z)Check the range of the given number type.Nz is not greater than r   )r
   minimummaximumnumber_types       r   _ranged_numberr    4   sl     KEuwEAAAABBBuwEAAAABBBLr   c                 ~    t          | t          t          f          s t          dt	          |            d          | S )zEnsure type number or fail.Could not convert type z to a number)
isinstancefloatintr   r	   r   s    r   type_numberr&   A   s@     eeS\** NL4;;LLLMMMLr   c                     t          | t                    sXt          | t                    r|                                 s t	          dt          |            d          t          |           } | S )zEnsure type integer or fail.r"   z to an integer)r#   r%   r$   
is_integerr   r	   r   s    r   type_integerr)   J   sm     eS!! %'' 	Tu/?/?/A/A 	TRtE{{RRRSSSE

Lr   c                 F    t          j        t          | |t                    S )z$Ensure typed number is within range.r   r   r   )r   r   r    r&   r   r   s     r   type_ranged_numberr-   U   s     ^Wg[fggggr   c                 F    t          j        t          | |t                    S )z%Ensured type integer is within range.r+   )r   r   r    r)   r,   s     r   type_ranged_integerr/   [   s     ^Wg[ghhhhr   c                 p    t          | t                    s t          dt          |            d          | S )zEnsure type boolean or fail.r"   z to a boolean)r#   boolr   r	   r   s    r   type_booleanr2   a   s<     eT"" OM4;;MMMNNNLr   c                 p    t          | t                    r| S t          dt          |            d          )zEnsure type string or fail.r"   z to a string)r#   strr   r	   r   s    r   type_stringr5   l   s;     % 
HtE{{HHH
I
IIr   c                 D    t          |                                           S )z&Ensure type string and normalize case.)r5   lowerr   s    r   type_string_insensitiver8   u   s     u##%%%r   c                     t          |           } t                              |           }|t          d          |                    d          S )z(Ensure type HTML attribute name or fail.Nz'A valid attribute name must be providedr   )r5   RE_IDENT	fullmatchr   group)r
   ms     r   type_html_identifierr>   {   sH     E5!!AyBCCC771::r   c                     g }t          |           } |                     |          D ]9}|                                }|s ||          }|                    |           :|S )zASplit the string by the delimiter and then parse with the parser.)r5   splitstripappend)stringr@   string_typelss        r   
_delimiterrG      sl     	A  F\\%    GGII 	KNN	Hr   c                 L     ||           } | |vrt          |  d|          | S )z1Ensure type string is within the accepted values.z not found in r   )r
   acceptedrD   s      r   
_string_inrJ      s?     KEHE====>>>Lr   Tc                 V    t          j        t          | |rt          nt                    S )z/Ensure type string is within the accepted list.)rI   rD   )r   r   rJ   r8   r5   )rI   insensitives     r   type_string_inrM      s2     /:K++   r   c                 :    t          j        t          | |          S )zString delimiter function.r@   rD   )r   r   rG   rO   s     r   type_string_delimiterrP      s     Zu+NNNNr   c                 t   t          | t                    st          d          i }|                                 D ]|\  }}t	          |          }|                                dk    rd}t          |          }n9|                                dk    rd}t	          |          }nt          |          }|||<   }|S )zAttribute dictionary.z2Attributes should be contained within a dictionaryclassid)r#   dictr   itemsr>   r7   type_html_classesr5   )r
   
attributeskvs       r   type_html_attribute_dictrZ      s     eT"" OMNNNJ 
 
1 ##7799A!!$$AAWWYY$A$Q''AAAA
1r    c                       e Zd ZdZdZdZi Zd Zd Zd Z	d Z
dd	Zd
 Zd Zd Zd Zed             Zd Zd Zd Zd Zd ZdS )BlockzBlock. Fc                 @   | j         | _        t          j        | j                  | _        d| j        v rt          d          i t          g| j        d<   || _        || _	        || _
        |j        | _        g | _        i | _        || _        |                                  dS )a  
        Initialize.

        - `length` specifies the length (number of slashes) that the header used
        - `tracker` is a persistent storage for the life of the current Markdown page.
          It is a dictionary where we can keep references until the parent extension is reset.
        - `md` is the Markdown object just in case access is needed to something we
          didn't think about.

        attrsz9'attrs' is a reserved option name and cannot be overridenN)ARGUMENTarg_speccopydeepcopyOPTIONSoption_specr   rZ   
_block_mgrlengthtrackermd	argumentsoptionsconfigon_init)selfrh   ri   	block_mgrrm   s        r   __init__zBlock.__init__   s     =66d&&&XYYY%')A$B!#,r   c                 6    | j                             |          S )zIs raw element.)rg   is_rawro   tags     r   rs   zBlock.is_raw   s     %%c***r   c                 6    | j                             |          S )zIs block element.)rg   is_blockrt   s     r   rw   zBlock.is_block   s     '',,,r   c                     |                     dd          }|                     dd          }|                     dd          }|S )zBasic html escaping.&z&amp;<z&lt;>z&gt;)replace)ro   texts     r   html_escapezBlock.html_escape   sB     ||C))||C((||C((r   Nc                    || j         j        }t          d          }t                              |          D ]}t          t          |          |          } t          ||          }t                              |fd|          S )zDedent raw text.Ninfc                 j    |                      d          dn|                      d          |d          S )N   r^      )r<   )r=   rE   s     r   <lambda>zBlock.dedent.<locals>.<lambda>  s5    1771::;QRRWXW^W^_`WaWabcbdbdWe r   )	rj   
tab_lengthr$   	RE_INDENTfindallminlen	RE_DEDENTsub)ro   r}   rh   
min_lengthxs        r   dedentzBlock.dedent  s     >W'F5\\
""4(( 	1 	1ASVVZ00JJV,,
}}eeegklllr   c                     dS )zOn initialize.Nr   ro   s    r   rn   zBlock.on_init  	     	r   c                     dS )z;Check how element should be treated by the Markdown parser.autor   r   s    r   on_markdownzBlock.on_markdown  s	     vr   c                    | j         |r| j         r	|s	| j         rdS || _        | j        }i }|                                D ]\  }}|d         ||<   |                                D ]@\  }}||vr dS ||         d         }|	  ||          }n# t          $ r Y  dS w xY w|||<   A|| _        |                     |          S )zParse configuration.NFr   r   )rb   argumentrf   rU   	Exceptionrl   on_validate)	ro   parentargrl   specparsedrX   rY   parsers	            r   	_validatezBlock._validate  s    M%C%%s%W[Wd%5 JJLL 	 	DAq!F1II MMOO 	 	DAq }}uu a%%"F1II$ % % %$uuu% F1II '''s   B
BBc                     dS )a  
        Handle validation event.

        Run after config parsing completes and allows for the opportunity
        to invalidate the block if argument, options, or even the parent
        element do not meet certain criteria.

        Return `False` to invalidate the block.
        Tr   ro   r   s     r   r   zBlock.on_validate@  s	     tr   c                     dS )z(Create the needed element and return it.Nr   r   s     r   	on_createzBlock.on_createM  s      r   c                    |                      |          }|j        }| j        d                                         D ]N\  }}|dk    r>||v r! t	          d          |d                   |z   }d                    |          |d<   I|||<   O|S )zCreate the element.r`   rR   r[   )r   attribrl   rU   rP   join)ro   r   elr   rX   rY   s         r   _createzBlock._createQ  s     ^^F## L)//11 	 	DAqG||;;2-c226'?CCaGA"%((1++wq			r   c                 &   |                                  }|                     |          }|dk    s|dk    rF|                     |          r1t          j        |                     |j                            |_        |                     |           dS )zCReached end of the block, dedent raw blocks and call `on_end` hook.rawr   N)r   on_addrs   mutilAtomicStringr   r}   on_end)ro   blockmodeadds       r   _endz
Block._endb  s     !!kk%  5==TV^^C0@0@^)$++ch*?*?@@CHEr   c                     dS )zPerform any action on end.Nr   ro   r   s     r   r   zBlock.on_endl  r   r   c                     |S )z
        Adjust where the content is added and return the desired element.

        Is there a sub-element where this content should go?
        This runs before processing every new block.
        r   r   s     r   r   zBlock.on_addq  s	     r   c                     dS )z1Perform action on the block after inline parsing.Nr   r   s     r   on_inline_endzBlock.on_inline_end{  r   r   N)__name__
__module____qualname____doc__NAMEra   re   rq   rs   rw   r~   r   rn   r   r   r   r   r   r   r   r   r   r   r   r   r   r]   r]      s#       L D HG  :+ + +
- - -
  m m m m  
  
%( %( %(N   7 7 ^7  "    
      r   r]   )	metaclassr   )NN)T)%r   abcr   r   r   rc   remarkdownr   r   compileIXr:   r   r   r   r   r   r   r    r&   r)   r-   r/   r2   type_ternaryr5   r8   r>   rG   rJ   rM   rP   rZ   rV   r]   r   r   r   <module>r      sJ     ' ' ' ' ' ' ' '      				 " " " " " "2: D24K  BJ+,,	BJ)**		V 	V 	V 	V6 6 6  7 7 7
 
 
    h h h hi i i i   z)\22J J J& & &           .9 O O O O  . *)#/CDD v v v v vg v v v v v vr   