
    e                        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Zdd	lmc mZ  G d
 de      Z G d de      Z G d de      Zd Zy	)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)AtomicStringNc                      e Zd ZdZd Zy)AbbrExtensionz- Abbreviation Extension for Python-Markdown. c                x    |j                   j                  j                  t        |j                         dd       y)z; Insert `AbbrPreprocessor` before `ReferencePreprocessor`. abbr   N)parserblockprocessorsregisterAbbrPreprocessor)selfmds     :/usr/lib/python3/dist-packages/markdown/extensions/abbr.pyextendMarkdownzAbbrExtension.extendMarkdown$   s)    
		!!**+;BII+FPRS    N)__name__
__module____qualname____doc__r    r   r   r   r   !   s    7Tr   r   c                  b    e Zd ZdZ ej
                  dej                        ZddZddZ	d	dZ
y)
r   z= Abbreviation Preprocessor - parse text for abbr references. z6^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$c                     y)NTr   )r   parentblocks      r   testzAbbrPreprocessor.test.   s    r   c                   |j                  d      }| j                  j                  |      }|r2|j                  d      j	                         }|j                  d      j	                         }| j
                  j                  j                  j                  t        | j                  |      |      d|z  d       ||j                         d j	                         r2|j                  d||j                         d j                  d             |d|j                          j	                         r2|j                  d|d|j                          j                  d             y|j                  d|       y	)
z
        Find and remove all Abbreviation references from the text.
        Each reference is set as a new `AbbrPattern` in the markdown instance.

        r   r   titlezabbr-%sr   N
TF)popREsearchgroupstripr   r   inlinePatternsr   AbbrInlineProcessor_generate_patternendinsertlstripstartrstrip)r   r   blocksr    mr   r#   s          r   runzAbbrPreprocessor.run1   s!    

1GGNN5!776?((*DGGG$**,EKKNN))22#D$:$:4$@%H)VZJZ\] QUUWX$$&aquuwx!7!7!=>Zaggi &&(az	!2!9!9$!?@ar   c                    t        |      }t        t        |            D ]  }d||   z  ||<    ddj                  |      z  S )z
        Given a string, returns an regex pattern to match that string.

        'HTML' -> r'(?P<abbr>[H][T][M][L])'

        Note: we force each char as a literal match (in brackets) as we don't
        know what they will be beforehand.

        z[%s]z(?P<abbr>\b%s\b) )listrangelenjoin)r   textcharsis       r   r,   z"AbbrPreprocessor._generate_patternJ   sJ     T
s5z" 	*Aq)E!H	*"chhuo66r   N)r   etree.Elementr    strreturnbool)r   r>   r2   z	list[str]r@   rA   )r;   r?   r@   r?   )r   r   r   r   recompile	MULTILINEr&   r!   r4   r,   r   r   r   r   r   )   s+    G	Mr||	\B27r   r   c                  ,     e Zd ZdZd fdZddZ xZS )r+   z Abbreviation inline pattern. c                2    t         |   |       || _        y )N)super__init__r#   )r   patternr#   	__class__s      r   rH   zAbbrInlineProcessor.__init__]   s    !
r   c                    t        j                  d      }t        |j                  d            |_        |j                  d| j                         ||j                  d      |j                  d      fS )Nr   r#   r   )	etreeElementr	   r(   r;   setr#   r0   r-   )r   r3   datar   s       r   handleMatchzAbbrInlineProcessor.handleMatcha   sS    }}V$ 1	$**%QWWQZq))r   )rI   r?   r#   r?   )r3   zre.Match[str]rO   r?   r@   ztuple[etree.Element, int, int])r   r   r   r   rH   rP   __classcell__)rJ   s   @r   r+   r+   Z   s    (*r   r+   c                     t        di | S )Nr   )r   )kwargss    r   makeExtensionrT   h   s    "6""r   )r   
__future__r   r6   r   r   r   inlinepatternsr   utilr	   rB   xml.etree.ElementTreerL   ElementTreer   r   r+   rT   r   r   r   <module>rZ      sP     #  , ,  	 % %TI T.7~ .7b*/ *#r   