
    -Ber                         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y)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y)AbbrExtensionz- Abbreviation Extension for Python-Markdown. c                 x    |j                   j                  j                  t        |j                         dd       y)z7 Insert AbbrPreprocessor before ReferencePreprocessor. abbr   N)parserblockprocessorsregisterAbbrPreprocessor)selfmds     8lib/python3.12/site-packages/markdown/extensions/abbr.pyextendMarkdownzAbbrExtension.extendMarkdown   s)    
		!!**+;BII+FPRS    N)__name__
__module____qualname____doc__r    r   r   r
   r
      s    7Tr   r
   c                   \    e Zd ZdZ ej
                  dej                        Zd Zd Z	d Z
y)r   z= Abbreviation Preprocessor - parse text for abbr references. z6^[*]\[(?P<abbr>[^\]]*)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$c                      y)NTr   )r   parentblocks      r   testzAbbrPreprocessor.test(   s    r   c                    |j                  d      }| j                  j                  |      }|r2|j                  d      j	                         }|j                  d      j	                         }| j
                  j                  j                  j                  t        | j                  |      |      d|z  d       ||j                         d j	                         r2|j                  d||j                         d j                  d             |d|j                          j	                         r2|j                  d|d|j                          j                  d             y|j                  d|       y	)
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+   s!    

1GGNN5!776?((*DGGG$**,EKKNN))22#D$:$:4$@%H)VZJZ\] QUUWX$$&aquuwx!7!7!=>Zaggi &&(az	!2!9!9$!?@ar   c                     t        |      }t        t        |            D ]  }d||   z  ||<    ddj                  |      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   sJ     T
s5z" 	*Aq)E!H	*"chhuo66r   N)r   r   r   r   recompile	MULTILINEr%   r    r3   r+   r   r   r   r   r   #   s+    G	Mr||	\B27r   r   c                   (     e Zd ZdZ fdZd Z xZS )r*   z Abbreviation inline pattern. c                 2    t         |   |       || _        y )N)super__init__r"   )r   patternr"   	__class__s      r   rC   zAbbrInlineProcessor.__init__W   s    !
r   c                     t        j                  d      }t        |j                  d            |_        |j                  d| j                         ||j                  d      |j                  d      fS )Nr   r"   r   )	etreeElementr   r'   r:   setr"   r/   r,   )r   r2   datar   s       r   handleMatchzAbbrInlineProcessor.handleMatch[   sS    }}V$ 1	$**%QWWQZq))r   )r   r   r   r   rC   rK   __classcell__)rE   s   @r   r*   r*   T   s    (*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      sM   $  , ,  	 % %TI T.7~ .7b*/ *#r   