a
    t=icr  ã                   @   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	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 )aç  
Abbreviation Extension for Python-Markdown
==========================================

This extension adds abbreviation handling to Python-Markdown.

See <https://Python-Markdown.github.io/extensions/abbreviations>
for documentation.

Oringinal code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/) and
 [Seemant Kulleen](http://www.kulleen.org/)

All changes Copyright 2008-2014 The Python Markdown Project

License: [BSD](https://opensource.org/licenses/bsd-license.php)

é   )Ú	Extensioné   )ÚBlockProcessor)ÚInlineProcessor)ÚAtomicStringé    Nc                   @   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 )z7 Insert AbbrPreprocessor before ReferencePreprocessor. Úabbré   N)ÚparserÚblockprocessorsÚregisterÚAbbrPreprocessor)ÚselfÚmd© r   úi/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/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 |¡}|rÂ| d¡ ¡ }| d¡ ¡ }| jjj t	|  
|¡|ƒd| d¡ || ¡ d…  ¡ rŒ| 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   ZinlinePatternsr   ÚAbbrInlineProcessorÚ_generate_patternÚendÚinsertÚlstripÚstartÚrstrip)r   r   Úblocksr   Úmr	   r   r   r   r   Úrun+   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#   D   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   r9   W   s    zAbbrInlineProcessor.__init__c                 C   s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr	   r   r   )	ÚetreeZElementr   r    r1   Úsetr   r'   r$   )r   r*   Údatar	   r   r   r   ÚhandleMatch[   s    
zAbbrInlineProcessor.handleMatch)r   r   r   r   r9   r@   Ú__classcell__r   r   r;   r   r"   T   s   r"   c                  K   s   t f i | ¤ŽS r7   )r   )Úkwargsr   r   r   ÚmakeExtensionb   s    rC   )r   r,   r   r   r   Zinlinepatternsr   Úutilr   r4   Zxml.etree.ElementTreer=   ZElementTreer   r   r"   rC   r   r   r   r   Ú<module>   s   1