
    j                        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c mZ  G d
 de          Z G d de          Z G d de          Z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                      e Zd ZdZd ZdS )AbbrExtensionz- Abbreviation Extension for Python-Markdown. c                l    |j         j                            t          |j                   dd           dS )z; Insert `AbbrPreprocessor` before `ReferencePreprocessor`. abbr   N)parserblockprocessorsregisterAbbrPreprocessor)selfmds     b/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/markdown/extensions/abbr.pyextendMarkdownzAbbrExtension.extendMarkdown$   s1    
	!**+;BI+F+FPRSSSSS    N)__name__
__module____qualname____doc__r    r   r   r   r   !   s.        77T T T T Tr   r   c                  V    e Zd ZdZ ej        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>.*)$parentetree.Elementblockstrreturnboolc                    dS )NTr   )r   r   r    s      r   testzAbbrPreprocessor.test.   s    tr   blocks	list[str]c                   |                     d          }| j                            |          }|r||                    d                                          }|                    d                                          }| j        j        j                            t          | 
                    |          |          d|z  d           ||                                d                                         rC|                    d||                                d                             d                     |d|                                                                         rC|                    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   inlinePatternsr   AbbrInlineProcessor_generate_patternendinsertlstripstartrstrip)r   r   r&   r    mr   r)   s          r   runzAbbrPreprocessor.run1   sz    

1GNN5!! 	776??((**DGGG$$**,,EKN)22#D$:$:4$@$@%HH)VZJZ\]   QUUWWXX$$&& ?aquuwwxx!7!7!=!=>>>ZaggiiZ &&(( Aaz		z!2!9!9$!?!?@@@4aur   textc                    t          |          }t          t          |                    D ]}d||         z  ||<   dd                    |          z  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   r:   charsis       r   r2   z"AbbrPreprocessor._generate_patternJ   sU     T

s5zz"" 	* 	*Aq)E!HH"chhuoo66r   N)r   r   r    r!   r"   r#   )r   r   r&   r'   r"   r#   )r:   r!   r"   r!   )r   r   r   r   recompile	MULTILINEr,   r%   r9   r2   r   r   r   r   r   )   sl        GG	Mr|	\	\B      27 7 7 7 7 7r   r   c                  ,     e Zd ZdZd fdZddZ xZS )r1   z Abbreviation inline pattern. patternr!   r)   c                X    t                                          |           || _        d S )N)super__init__r)   )r   rG   r)   	__class__s      r   rJ   zAbbrInlineProcessor.__init__]   s&    !!!


r   r8   re.Match[str]datar"   tuple[etree.Element, int, int]c                   t          j        d          }t          |                    d                    |_        |                    d| j                   ||                    d          |                    d          fS )Nr   r)   r   )	etreeElementr	   r.   r:   setr)   r6   r3   )r   r8   rM   r   s       r   handleMatchzAbbrInlineProcessor.handleMatcha   sa    }V$$ 11	$*%%%QWWQZZq))r   )rG   r!   r)   r!   )r8   rL   rM   r!   r"   rN   )r   r   r   r   rJ   rS   __classcell__)rK   s   @r   r1   r1   Z   sW        ((     * * * * * * * *r   r1   c                     t          di | S )Nr   )r   )kwargss    r   makeExtensionrW   h   s    ""6"""r   )r   
__future__r   r<   r   r   r   inlinepatternsr   utilr	   rC   xml.etree.ElementTreerP   ElementTreer   r   r1   rW   r   r   r   <module>r]      s/     # " " " " "       , , , , , , , , , , , ,       				 % % % % % % % % %T T T T TI T T T.7 .7 .7 .7 .7~ .7 .7 .7b* * * * */ * * *# # # # #r   