
    $g                    X   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZmZ dd
lmZ ddlZddlmc mZ erddlmZ ddlmZ  G d de          Z G d de
          Z G d de          Z  ed          e          Z ed           G d de                      Zd ZdS )z
This extension adds abbreviation handling to Python-Markdown.

See the [documentation](https://Python-Markdown.github.io/extensions/abbreviations)
for details.
    )annotations   )	Extension   )BlockProcessor)InlineProcessor)Treeprocessor)AtomicString
deprecated)TYPE_CHECKINGN)Markdown)BlockParserc                  <     e Zd ZdZ fdZd Zd Zd	dZd Z xZ	S )
AbbrExtensionz- Abbreviation Extension for Python-Markdown. c                n    di dgi| _         	  t                      j        di | i | _        i | _        dS )z( Initiate Extension and set up configs. glossaryz`A dictionary where the `key` is the abbreviation and the `value` is the definition.Default: `{}`N )configsuper__init__abbrsr   )selfkwargs	__class__s     X/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/markdown/extensions/abbr.pyr   zAbbrExtension.__init__*   sR      
 	/""6"""
    c                    | j                                          | j        r!| j                             | j                   dS dS )z- Clear all previously defined abbreviations. N)r   clearr   updater   s    r   resetzAbbrExtension.reset8   sH    
M 	-Jdm,,,,,	- 	-r   c                8    | j                                          dS )z, Clear all abbreviations from the glossary. N)r   r   r    s    r   reset_glossaryzAbbrExtension.reset_glossary>   s    r   
dictionarydict[str, str]c                .    |ri || j         | _         dS dS )z\Adds `dictionary` to our glossary. Any abbreviations that already exist will be overwritten.N)r   )r   r$   s     r   load_glossaryzAbbrExtension.load_glossaryB   s+     	<;z;T];DMMM	< 	<r   c                   | j         d         d         r&|                     | j         d         d                    | j                            | j                   |                    |            |j                            t          || j                  dd           |j	        j
                            t          |j	        | j                  dd           dS )z6 Insert `AbbrTreeprocessor` and `AbbrBlockprocessor`. r   r   abbr      N)r   r'   r   r   r   registerExtensiontreeprocessorsregisterAbbrTreeprocessorparserblockprocessorsAbbrBlockprocessor)r   mds     r   extendMarkdownzAbbrExtension.extendMarkdownG   s    K
#A& 	;t{:6q9:::
$-(((
T"""
""#4R#D#DfaPPP
	!**+=bi+T+TV\^`aaaaar   )r$   r%   )
__name__
__module____qualname____doc__r   r!   r#   r'   r4   __classcell__r   s   @r   r   r   '   s        77    - - -  < < < <
b b b b b b br   r   c                  8     e Zd ZdZdd fdZdddZddZ xZS )r/   z3 Replace abbreviation text with `<abbr>` elements. Nr3   Markdown | Noner   dict | Nonec                n    ||ni | _         d | _        t                                          |           d S N)r   REr   r   )r   r3   r   r   s      r   r   zAbbrTreeprocessor.__init__T   s8    $)$5552
)-r   eletree.Elementparentetree.Element | NonereturnNonec           	        t          |          D ]}|                     ||           |j        x}rt          t          | j                            |                              D ]}| j        |                    d                   rt          j	        dd| j        |                    d                   i          }t          |                    d                    |_        ||                                d         |_        |                    d|           |d|                                         }||_        |#|j        r|j        }t          |                              |          dz   }t          t          | j                            |                              D ]}t          j	        dd| j        |                    d                   i          }t          |                    d                    |_        ||                                d         |_        |                    ||           |d|                                         }||_        dS dS dS )zW Recursively iterate over elements, run regex on text and wrap matches in `abbr` tags. r   r)   titleNr   )reversediter_elementtextlistr@   finditerr   groupetreeElementr
   endtailinsertstartindex)	r   rA   rC   childrK   mr)   rR   rU   s	            r   rJ   zAbbrTreeprocessor.iter_elementY   s   b\\ 	) 	)EeR((((7?4 	d47#3#3D#9#9::;; , ,:aggajj) , ='4:aggajj;Q1RSSD ,QWWQZZ 8 8DI $QUUWWXXDIIIa&&&

+DBG"'7DLL&&r**Q.Ed47#3#3D#9#9::;; ( (}Vgtz!''!**7M-NOO(44	 N	eT***JQWWYYJ'BGGG r   rootc                :   | j         sdS t          | j                                                   }|                    t          d           t          j        dd                    d |D                        d          | _        | 	                    |           dS )z0 Step through tree to find known abbreviations. NT)keyreversez\b(?:|c              3  >   K   | ]}t          j        |          V  d S r?   )reescape).0rZ   s     r   	<genexpr>z(AbbrTreeprocessor.run.<locals>.<genexpr>y   s*      /T/T3	#/T/T/T/T/T/Tr   z)\b)
r   rL   keyssortlenr^   compilejoinr@   rJ   )r   rX   	abbr_lists      r   runzAbbrTreeprocessor.runq   s    z 	F**++	3---*[sxx/T/T)/T/T/T'T'T[[[\\$r   )NN)r3   r<   r   r=   r?   )rA   rB   rC   rD   rE   rF   )rX   rB   rE   rD   )r5   r6   r7   r8   r   rJ   rh   r9   r:   s   @r   r/   r/   Q   su        ==      
    0
  
  
  
  
  
  
  
 r   r/   c                  `     e Zd ZdZ ej        dej                  Zd fdZddZ	ddZ
 xZS )r2   z) Parse text for abbreviation references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$r0   r   r   dictc                X    || _         t                                          |           d S r?   )r   r   r   )r   r0   r   r   s      r   r   zAbbrBlockprocessor.__init__   s(     
     r   rC   rB   blockstrrE   boolc                    dS )NTr   )r   rC   rl   s      r   testzAbbrBlockprocessor.test   s    tr   blocks	list[str]c                h   |                     d          }| j                            |          }|ri|                    d                                          }|                    d                                          }|r|r|dk    s|dk    r| j                             |           n
|| j        |<   ||                                d                                         rC|                    d||                                d                             d                     |d|	                                                                         rC|                    d|d|	                                         
                    d                     dS |                    d|           d	S )
z
        Find and remove all abbreviation references from the text.
        Each reference is added to the abbreviation collection.

        r   r)   rH   z''z""N
TF)popr@   searchrN   stripr   rQ   rS   lstriprT   rstrip)r   rC   rq   rl   rW   r)   rH   s          r   rh   zAbbrBlockprocessor.run   sw    

1GNN5!! 	776??((**DGGG$$**,,E  D==ETMMJNN4((((',DJt$?((** CMM!U1557788_%;%;D%A%ABBB!''))$**,, EMM!U:AGGII:%6%=%=d%C%CDDDtaur   )r0   r   r   rj   )rC   rB   rl   rm   rE   rn   )rC   rB   rq   rr   rE   rn   )r5   r6   r7   r8   r^   re   	MULTILINEr@   r   rp   rh   r9   r:   s   @r   r2   r2   ~   s        33	NPRP\	]	]B! ! ! ! ! !          r   r2   z4This class has been renamed to `AbbrBlockprocessor`.zJThis class will be removed in the future; use `AbbrTreeprocessor` instead.c                  ,     e Zd ZdZd fdZddZ xZS )AbbrInlineProcessorz Abbreviation inline pattern. patternrm   rH   c                X    t                                          |           || _        d S r?   )r   r   rH   )r   r}   rH   r   s      r   r   zAbbrInlineProcessor.__init__   s&    !!!


r   rW   re.Match[str]datarE   tuple[etree.Element, int, int]c                   t          j        d          }t          |                    d                    |_        |                    d| j                   ||                    d          |                    d          fS )Nr)   rH   r   )	rO   rP   r
   rN   rK   setrH   rT   rQ   )r   rW   r   r)   s       r   handleMatchzAbbrInlineProcessor.handleMatch   sa    }V$$ 11	$*%%%QWWQZZq))r   )r}   rm   rH   rm   )rW   r   r   rm   rE   r   )r5   r6   r7   r8   r   r   r9   r:   s   @r   r|   r|      sW        ((     * * * * * * * *r   r|   c                     t          di | S )Nr   )r   )r   s    r   makeExtensionr      s    ""6"""r   )r8   
__future__r    r   r1   r   inlinepatternsr   r-   r	   utilr
   r   typingr   r^   xml.etree.ElementTreerO   ElementTreer   blockparsersr   r   r/   r2   AbbrPreprocessorr|   r   r   r   r   <module>r      s     # " " " " "       , , , , , , , , , , , , * * * * * * + + + + + + + +             				 % % % % % % % % % +******'b 'b 'b 'b 'bI 'b 'b 'bT*  *  *  *  *  *  *  * Z% % % % % % % %P V::TUUVhii  XYY* * * * */ * * ZY*# # # # #r   