o
    7÷dw  ã                   @   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.

Original 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 )z; Insert `AbbrPreprocessor` before `ReferencePreprocessor`. Úabbré   N)ÚparserÚblockprocessorsÚregisterÚAbbrPreprocessor)ÚselfÚmd© r   úoC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\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   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   r8   W   s   
zAbbrInlineProcessor.__init__c                 C   s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr	   r   r   )	ÚetreeÚElementr   r    r1   Úsetr   r'   r$   )r   r*   Údatar	   r   r   r   ÚhandleMatch[   s   
zAbbrInlineProcessor.handleMatch)r   r   r   r   r8   r@   Ú__classcell__r   r   r:   r   r"   T   s    r"   c                  K   s   t di | ¤ŽS )Nr   )r   )Úkwargsr   r   r   ÚmakeExtensionb   s   rC   )r   r,   r   r   r   Zinlinepatternsr   Úutilr   r4   Úxml.etree.ElementTreer<   ÚElementTreer   r   r"   rC   r   r   r   r   Ú<module>   s    1