o
    ¼>hå  ã                   @  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mZ ddlZddlm  mZ erIddlmZ ddlmZ G dd„ deƒZG dd„ de
ƒZG dd„ deƒZedƒeƒZedƒ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)ÚTreeprocessor)ÚAtomicStringÚ
deprecated)ÚTYPE_CHECKINGN)ÚMarkdown)ÚBlockParserc                      sB   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd
d„Zdd„ Z‡  Z	S )ÚAbbrExtensionz- Abbreviation Extension for Python-Markdown. c                   s2   di dgi| _ 	 tƒ jdi |¤Ž i | _i | _dS )z( Initiate Extension and set up configs. Úglossaryz`A dictionary where the `key` is the abbreviation and the `value` is the definition.Default: `{}`N© )ÚconfigÚsuperÚ__init__Úabbrsr   )ÚselfÚkwargs©Ú	__class__r   úx/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/markdown/extensions/abbr.pyr   *   s   þÿ
zAbbrExtension.__init__c                 C  s&   | j  ¡  | jr| j  | j¡ dS dS )z- Clear all previously defined abbreviations. N)r   Úclearr   Úupdate©r   r   r   r   Úreset8   s   
ÿzAbbrExtension.resetc                 C  s   | j  ¡  dS )z, Clear all abbreviations from the glossary. N)r   r   r   r   r   r   Úreset_glossary>   s   zAbbrExtension.reset_glossaryÚ
dictionaryúdict[str, str]c                 C  s   |ri |¥| j ¥| _ dS dS )z\Adds `dictionary` to our glossary. Any abbreviations that already exist will be overwritten.N)r   )r   r   r   r   r   Úload_glossaryB   s   ÿzAbbrExtension.load_glossaryc                 C  sr   | j d d r|  | j d d ¡ | j | j¡ | | ¡ |j t|| jƒdd¡ |j	j
 t|j	| jƒdd¡ dS )z6 Insert `AbbrTreeprocessor` and `AbbrBlockprocessor`. r   r   Úabbré   é   N)r   r!   r   r   r   ÚregisterExtensionÚtreeprocessorsÚregisterÚAbbrTreeprocessorÚparserÚblockprocessorsÚAbbrBlockprocessor)r   Úmdr   r   r   ÚextendMarkdownG   s   
 zAbbrExtension.extendMarkdown)r   r    )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r!   r-   Ú__classcell__r   r   r   r   r   '   s    
r   c                      sD   e Zd ZdZdd‡ fdd„Zddd„Zdddd„Zddd„Z‡  ZS ) r(   z3 Replace abbreviation text with `<abbr>` elements. Nr,   úMarkdown | Noner   údict | Nonec                   s(   |d ur|ni | _ d | _tƒ  |¡ d S ©N)r   ÚREr   r   )r   r,   r   r   r   r   r   T   s   zAbbrTreeprocessor.__init__ÚtitleÚstrÚtextÚtailÚreturnúetree.Elementc                 C  s$   t  dd|i¡}t|ƒ|_||_|S )z Create an `abbr` element. r"   r7   )ÚetreeÚElementr	   r9   r:   )r   r7   r9   r:   r"   r   r   r   Úcreate_elementY   s   
z AbbrTreeprocessor.create_elementÚelÚparentúetree.Element | NoneÚNonec           	      C  sN  t |ƒD ]}|  ||¡ q|j }rSt|tƒsSt t| j |¡ƒƒD ].}| j| 	d¡ rO|  
| j| 	d¡ | 	d¡|| ¡ d… ¡}| d|¡ |d| ¡ … }q!||_|dur¡|jr£|j}t|ƒ |¡d }t|tƒs¥t t| j |¡ƒƒD ]&}|  
| j| 	d¡ | 	d¡|| ¡ d… ¡}| ||¡ |d| ¡ … }qu||_dS dS dS dS )zW Recursively iterate over elements, run regex on text and wrap matches in `abbr` tags. r   Nr   )ÚreversedÚiter_elementr9   Ú
isinstancer	   Úlistr6   Úfinditerr   Úgroupr?   ÚendÚinsertÚstartr:   Úindex)	r   r@   rA   Úchildr9   Úmr"   r:   rM   r   r   r   rE   `   s,   

,€
,
øzAbbrTreeprocessor.iter_elementÚrootc                 C  sX   | j sdS t| j  ¡ ƒ}|jtdd t dd dd„ |D ƒ¡› d¡| _|  	|¡ dS )	z0 Step through tree to find known abbreviations. NT)ÚkeyÚreversez\b(?:ú|c                 s  s    | ]}t  |¡V  qd S r5   )ÚreÚescape)Ú.0rQ   r   r   r   Ú	<genexpr>~   s   € z(AbbrTreeprocessor.run.<locals>.<genexpr>z)\b)
r   rG   ÚkeysÚsortÚlenrT   ÚcompileÚjoinr6   rE   )r   rP   Ú	abbr_listr   r   r   Úrunv   s   $zAbbrTreeprocessor.run)NN)r,   r3   r   r4   )r7   r8   r9   r8   r:   r8   r;   r<   r5   )r@   r<   rA   rB   r;   rC   )rP   r<   r;   rB   )	r.   r/   r0   r1   r   r?   rE   r^   r2   r   r   r   r   r(   Q   s    
r(   c                      sD   e Zd ZdZe dej¡Zd‡ fdd„Zddd„Z	ddd„Z
‡  ZS )r+   z) Parse text for abbreviation references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$r)   r   r   Údictc                   s   || _ tƒ  |¡ d S r5   )r   r   r   )r   r)   r   r   r   r   r   ˆ   s   zAbbrBlockprocessor.__init__rA   r<   Úblockr8   r;   Úboolc                 C  s   dS )NTr   )r   rA   r`   r   r   r   ÚtestŒ   s   zAbbrBlockprocessor.testÚblocksú	list[str]c                 C  sÞ   |  d¡}| j |¡}|rg| d¡ ¡ }| d¡ ¡ }|rg|rg|dks'|dkr.| j  |¡ n|| j|< || ¡ d…  ¡ rL| d|| ¡ d…  d¡¡ |d| 	¡ …  ¡ re| d|d| 	¡ …  
d¡¡ dS | d|¡ d	S )
z
        Find and remove all abbreviation references from the text.
        Each reference is added to the abbreviation collection.

        r   r"   r7   z''z""NÚ
TF)Úpopr6   ÚsearchrI   Ústripr   rJ   rK   ÚlstriprL   Úrstrip)r   rA   rc   r`   rO   r"   r7   r   r   r   r^      s    

zAbbrBlockprocessor.run)r)   r   r   r_   )rA   r<   r`   r8   r;   ra   )rA   r<   rc   rd   r;   ra   )r.   r/   r0   r1   rT   r[   Ú	MULTILINEr6   r   rb   r^   r2   r   r   r   r   r+   ƒ   s    
r+   z4This class has been renamed to `AbbrBlockprocessor`.zJThis class will be removed in the future; use `AbbrTreeprocessor` instead.c                      s,   e Zd ZdZd‡ fdd„Zddd„Z‡  ZS )ÚAbbrInlineProcessorz Abbreviation inline pattern. Úpatternr8   r7   c                   s   t ƒ  |¡ || _d S r5   )r   r   r7   )r   rm   r7   r   r   r   r   ²   s   
zAbbrInlineProcessor.__init__rO   úre.Match[str]Údatar;   útuple[etree.Element, int, int]c                 C  s>   t  d¡}t| d¡ƒ|_| d| j¡ || d¡| d¡fS )Nr"   r7   r   )	r=   r>   r	   rI   r9   Úsetr7   rL   rJ   )r   rO   ro   r"   r   r   r   ÚhandleMatch¶   s   
zAbbrInlineProcessor.handleMatch)rm   r8   r7   r8   )rO   rn   ro   r8   r;   rp   )r.   r/   r0   r1   r   rr   r2   r   r   r   r   rl   ®   s    rl   c                  K  s   t di | ¤ŽS )Nr   )r   )r   r   r   r   ÚmakeExtension½   s   rs   )r1   Ú
__future__r   Ú r   r*   r   Úinlinepatternsr   r&   r   Úutilr	   r
   Útypingr   rT   Úxml.etree.ElementTreer=   ÚElementTreer   Úblockparserr   r   r(   r+   ÚAbbrPreprocessorrl   rs   r   r   r   r   Ú<module>   s(   *2(