o
    „¿ÑgJ  ã                   @  s–   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  mZ G d
d„ deƒZG dd„ deƒZG dd„ deƒZd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)ÚAtomicStringNc                   @  s   e Zd ZdZdd„ ZdS )ÚAbbrExtensionz- Abbreviation Extension for Python-Markdown. c                 C  s   |j j t|j ƒdd¡ dS )z; Insert `AbbrPreprocessor` before `ReferencePreprocessor`. Úabbré   N)ÚparserÚblockprocessorsÚregisterÚAbbrPreprocessor)ÚselfÚmd© r   úX/var/www/html/bloggers_ems/venv/lib/python3.10/site-packages/markdown/extensions/abbr.pyÚextendMarkdown$   s   zAbbrExtension.extendMarkdownN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r	   !   s    r	   c                   @  s6   e Zd ZdZe dej¡Zdd„ Zdd„ Z	dd„ Z
d	S )
r   z= Abbreviation Preprocessor - parse text for abbr references. z6^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$c                 C  s   dS )NTr   )r   ÚparentÚblockr   r   r   Útest.   s   zAbbrPreprocessor.testc                 C  sÒ   |  d¡}| j |¡}|ra| d¡ ¡ }| d¡ ¡ }| jjj t	|  
|¡|ƒd| d¡ || ¡ d…  ¡ rF| d|| ¡ d…  d¡¡ |d| ¡ …  ¡ r_| d|d| ¡ …  d¡¡ dS | d|¡ d	S )
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   r   r   r   Úrun1   s   

ÿzAbbrPreprocessor.runc                 C  s8   t |ƒ}tt|ƒƒD ]
}d||  ||< q
dd |¡ 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Úir   r   r   r%   J   s   
z"AbbrPreprocessor._generate_patternN)r   r   r   r   ÚreÚcompileÚ	MULTILINEr   r   r-   r%   r   r   r   r   r   )   s    r   c                      s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )r$   z Abbreviation inline pattern. c                   s   t ƒ  |¡ || _d S )N)ÚsuperÚ__init__r   )r   Úpatternr   ©Ú	__class__r   r   r:   ]   s   
zAbbrInlineProcessor.__init__c                 C  s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr
   r   r   )	ÚetreeÚElementr   r!   r3   Úsetr   r)   r&   )r   r,   Údatar
   r   r   r   ÚhandleMatcha   s   
zAbbrInlineProcessor.handleMatch)r   r   r   r   r:   rB   Ú__classcell__r   r   r<   r   r$   Z   s    r$   c                  K  s   t di | ¤ŽS )Nr   )r	   )Úkwargsr   r   r   ÚmakeExtensionh   s   rE   )r   Ú
__future__r   r.   r   r   r   Úinlinepatternsr   Úutilr   r6   Úxml.etree.ElementTreer>   ÚElementTreer	   r   r$   rE   r   r   r   r   Ú<module>   s   1