
    cr                         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c mZ  G d	 d
e          Z G d de          Z G d de          Z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.

Oringinal 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                       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 )z7 Insert AbbrPreprocessor before ReferencePreprocessor. abbr   N)parserblockprocessorsregisterAbbrPreprocessor)selfmds     8lib/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                   P    e Zd ZdZ ej        dej                  Zd Zd Z	d Z
dS )r   z= Abbreviation Preprocessor - parse text for abbr references. z6^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$c                     dS )NTr   )r   parentblocks      r   testzAbbrPreprocessor.test(   s    tr   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   blocksr   mr   r"   s          r   runzAbbrPreprocessor.run+   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   c                     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   textcharsis       r   r+   z"AbbrPreprocessor._generate_patternD   sU     T

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


r   c                    t          j        d          }t          |                    d                    |_        |                    d| j                   ||                    d          |                    d          fS )Nr   r"   r   )	etreeElementr   r'   r:   setr"   r/   r,   )r   r2   datar   s       r   handleMatchzAbbrInlineProcessor.handleMatch[   sa    }V$$ 11	$*%%%QWWQZZq))r   )r   r   r   r   rC   rK   __classcell__)rE   s   @r   r*   r*   T   sM        ((    * * * * * * *r   r*   c                      t          di | S )Nr   )r
   )kwargss    r   makeExtensionrO   b   s    ""6"""r   )r   r5   r   r   r   inlinepatternsr   utilr   r=   xml.etree.ElementTreerG   ElementTreer
   r   r*   rO   r   r   r   <module>rT      s   $       , , , , , , , , , , , ,       				 % % % % % % % % %T T T T TI T T T.7 .7 .7 .7 .7~ .7 .7 .7b* * * * */ * * *# # # # #r   