a
     Df                     @  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   e/nfs/NAS7/SABIOD/METHODE/ermites/ermites_venv/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                   @  sR   e Zd ZdZedejZddddddZdd	dd
ddZ	dddddZ
dS )r   z= Abbreviation Preprocessor - parse text for abbr references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$zetree.Elementstrbool)parentblockreturnc                 C  s   dS )NTr   )r   r   r   r   r   r   test.   s    zAbbrPreprocessor.testz	list[str])r   blocksr   c                 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   r   r   mr
   r    r   r   r   run1   s    

zAbbrPreprocessor.run)textr   c                 C  s   dt | dS )z? Given a string, returns a regex pattern to match that string. z(?P<abbr>\bz\b))reescape)r   r0   r   r   r   r(   J   s    z"AbbrPreprocessor._generate_patternN)r   r   r   r   r1   compile	MULTILINEr#   r   r/   r(   r   r   r   r   r   )   s
   r   c                      s:   e Zd ZdZddd fddZddddd	d
Z  ZS )r'   z Abbreviation inline pattern. r   )patternr    c                   s   t  | || _d S N)super__init__r    )r   r5   r    	__class__r   r   r8   R   s    zAbbrInlineProcessor.__init__zre.Match[str]ztuple[etree.Element, int, int])r.   datar   c                 C  s>   t d}t|d|_|d| j ||d|dfS )Nr
   r    r   )	etreeElementr   r%   r0   setr    r,   r)   )r   r.   r;   r
   r   r   r   handleMatchV   s    
zAbbrInlineProcessor.handleMatch)r   r   r   r   r8   r?   __classcell__r   r   r9   r   r'   O   s   r'   c                  K  s   t f i | S r6   )r	   )kwargsr   r   r   makeExtension]   s    rB   )r   
__future__r    r   r   r   Zinlinepatternsr   utilr   r1   xml.etree.ElementTreer<   ElementTreer	   r   r'   rB   r   r   r   r   <module>   s   &