o
    ñ+óe²  ã                   @  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   ú8lib/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                   @  s<   e Zd ZdZe dej¡Zdd	d
„Zddd„Z	ddd„Z
dS )r   z= Abbreviation Preprocessor - parse text for abbr references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$Úparentúetree.ElementÚblockÚstrÚreturnÚboolc                 C  s   dS )NTr   )r   r   r   r   r   r   Útest.   s   zAbbrPreprocessor.testÚblocksú	list[str]c                 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   ZinlinePatternsr   ÚAbbrInlineProcessorÚ_generate_patternÚendÚinsertÚlstripÚstartÚrstrip)r   r   r    r   Úmr
   r"   r   r   r   Úrun1   s   

ÿzAbbrPreprocessor.runÚtextc                 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   r2   r   r   r   r*   J   s   z"AbbrPreprocessor._generate_patternN)r   r   r   r   r   r   )r   r   r    r!   r   r   )r2   r   r   r   )r   r   r   r   r3   ÚcompileÚ	MULTILINEr%   r   r1   r*   r   r   r   r   r   )   s    

r   c                      s,   e Zd ZdZd‡ fdd„Zddd„Z‡  ZS )r)   z Abbreviation inline pattern. Úpatternr   r"   c                   s   t ƒ  |¡ || _d S )N)ÚsuperÚ__init__r"   )r   r7   r"   ©Ú	__class__r   r   r9   R   s   
zAbbrInlineProcessor.__init__r0   úre.Match[str]Údatar   útuple[etree.Element, int, int]c                 C  s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr
   r"   r   )	ÚetreeZElementr   r'   r2   Úsetr"   r.   r+   )r   r0   r=   r
   r   r   r   ÚhandleMatchV   s   
zAbbrInlineProcessor.handleMatch)r7   r   r"   r   )r0   r<   r=   r   r   r>   )r   r   r   r   r9   rA   Ú__classcell__r   r   r:   r   r)   O   s    r)   c                  K  s   t di | ¤ŽS )Nr   )r	   )Úkwargsr   r   r   ÚmakeExtension]   s   rD   )r   Z
__future__r   Ú r   r   r   Zinlinepatternsr   Úutilr   r3   Zxml.etree.ElementTreer?   ZElementTreer	   r   r)   rD   r   r   r   r   Ú<module>   s   &