U
    ôDk\°  ã                   @   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
mZmZ dd
lZe d¡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](http://www.opensource.org/licenses/bsd-license.php)

é    )Úabsolute_import)Úunicode_literalsé   )Ú	Extensioné   )ÚPreprocessor)ÚInlineProcessor)ÚetreeÚAtomicStringNz,[*]\[(?P<abbr>[^\]]*)\][ ]?:\s*(?P<title>.*)c                   @   s   e Zd ZdZdd„ ZdS )ÚAbbrExtensionz- Abbreviation Extension for Python-Markdown. c                 C   s   |j  t|ƒdd¡ dS )z7 Insert AbbrPreprocessor before ReferencePreprocessor. Úabbré   N)ÚpreprocessorsÚregisterÚAbbrPreprocessor)ÚselfÚmd© r   ú:/usr/lib/python3/dist-packages/markdown/extensions/abbr.pyÚextendMarkdown"   s    zAbbrExtension.extendMarkdownN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )r   z= Abbreviation Preprocessor - parse text for abbr references. c                 C   st   g }|D ]f}t  |¡}|rd| d¡ ¡ }| d¡ ¡ }| jj t|  |¡|ƒd| d¡ | 	d¡ q| 	|¡ q|S )zš
        Find and remove all Abbreviation references from the text.
        Each reference is set as a new AbbrPattern in the markdown instance.

        r   Útitlezabbr-%sr   Ú )
ÚABBR_REF_REÚmatchÚgroupÚstripr   ZinlinePatternsr   ÚAbbrInlineProcessorÚ_generate_patternÚappend)r   ÚlinesZnew_textÚlineÚ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)r   )ÚlistÚrangeÚlenÚjoin)r   ÚtextÚcharsÚir   r   r   r!   @   s    
z"AbbrPreprocessor._generate_patternN)r   r   r   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 t| ƒ |¡ || _d S ©N)Úsuperr    Ú__init__r   )r   Úpatternr   ©Ú	__class__r   r   r0   S   s    zAbbrInlineProcessor.__init__c                 C   s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr   r   r   )	r	   ZElementr
   r   r+   Úsetr   ÚstartÚend)r   r%   Údatar   r   r   r   ÚhandleMatchW   s    
zAbbrInlineProcessor.handleMatch)r   r   r   r   r0   r8   Ú__classcell__r   r   r2   r   r    P   s   r    c                  K   s
   t f | ŽS r.   )r   )Úkwargsr   r   r   ÚmakeExtension^   s    r;   )r   Z
__future__r   r   r   r   r   r   Zinlinepatternsr   Úutilr	   r
   ÚreÚcompiler   r   r   r    r;   r   r   r   r   Ú<module>   s   
)