
    Ug                    0   S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	KJrJr  SS
KJr  SSKrSSKJs  Jr  \(       a  SSKJr  SSKJr   " S S\5      r " S S\
5      r " S S\5      r\" S5      " \5      r\" S5       " S S\5      5       rS rg)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                  H   ^  \ rS rSrSrU 4S jrS rS rS	S jrS r	Sr
U =r$ )
AbbrExtension'   z,Abbreviation Extension for Python-Markdown. c                Z   > S0 S/0U l          [        TU ]  " S0 UD6  0 U l        0 U l        g)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__s     :/usr/lib/python3/dist-packages/markdown/extensions/abbr.pyr   AbbrExtension.__init__*   sA      
 	/"6"
    c                    U R                   R                  5         U R                  (       a&  U R                   R                  U R                  5        gg)z,Clear all previously defined abbreviations. N)r   clearr   updater   s    r   resetAbbrExtension.reset8   s4    

MMJJdmm, r   c                8    U R                   R                  5         g)z+Clear all abbreviations from the glossary. N)r   r    r"   s    r   reset_glossaryAbbrExtension.reset_glossary>   s    r   c                >    U(       a  0 UEU R                   EU l         gg)z\Adds `dictionary` to our glossary. Any abbreviations that already exist will be overwritten.N)r   )r   
dictionarys     r   load_glossaryAbbrExtension.load_glossaryB   s    ;z;T]];DM r   c                   U R                   S   S   (       a!  U R                  U R                   S   S   5        U R                  R                  U R                  5        UR                  U 5        UR                  R                  [        XR                  5      SS5        UR                  R                  R                  [        UR                  U R                  5      SS5        g)z5Insert `AbbrTreeprocessor` and `AbbrBlockprocessor`. r   r   abbr      N)r   r*   r   r!   r   registerExtensiontreeprocessorsregisterAbbrTreeprocessorparserblockprocessorsAbbrBlockprocessor)r   mds     r   extendMarkdownAbbrExtension.extendMarkdownG   s    KK
#A&t{{:6q9:

$--(
T"
""#4R#DfaP
		!!**+=bii+TV\^`ar   )r   r   r   )r)   zdict[str, str])__name__
__module____qualname____firstlineno____doc__r   r#   r&   r*   r8   __static_attributes____classcell__r   s   @r   r   r   '   s&    7-<
b br   r   c                  L   ^  \ rS rSrSrSSU 4S jjjrS	S
S jjrSS jrSrU =r	$ )r3   Q   z2Replace abbreviation text with `<abbr>` elements. c                J   > Ub  UO0 U l         S U l        [        TU ]  U5        g N)r   REr   r   )r   r7   r   r   s      r   r   AbbrTreeprocessor.__init__T   s%    $)$552
)-r   c           	     `   [        U5       H  nU R                  X15        M     UR                  =n(       a  [        [        U R                  R                  U5      5      5       H  nU R                  UR                  S5         (       d  M(  [        R                  " SSU R                  UR                  S5         05      n[        UR                  S5      5      Ul        XER                  5       S Ul        UR                  SU5        USUR                  5        nM     XAl        UGb  UR                  (       a  UR                  n[        U5      R                  U5      S-   n[        [        U R                  R                  U5      5      5       H  n[        R                  " SSU R                  UR                  S5         05      n[        UR                  S5      5      Ul        XuR                  5       S Ul        UR                  X5        USUR                  5        nM     Xql        ggg)zVRecursively iterate over elements, run regex on text and wrap matches in `abbr` tags. r   r-   titleNr   )reversediter_elementtextlistrF   finditerr   groupetreeElementr
   endtailinsertstartindex)	r   elparentchildrL   mr-   rS   rV   s	            r   rK   AbbrTreeprocessor.iter_elementY   s   b\Ee( "77?4?d477#3#3D#9:;::aggaj)) =='4::aggaj;Q1RSD ,QWWQZ 8DI $UUWXDIIIa&
+D < G"''77DL&&r*Q.Ed477#3#3D#9:;}}Vgtzz!''!*7M-NO(4	 N	e*JQWWY' < G #*r   c                "   U R                   (       d  g[        U R                   R                  5       5      nUR                  [        SS9  [
        R                  " SSR                  S U 5       5       S35      U l        U R                  U5        g)z/Step through tree to find known abbreviations. NT)keyreversez\b(?:|c              3  N   #    U  H  n[         R                  " U5      v   M     g 7frE   )reescape).0r]   s     r   	<genexpr>(AbbrTreeprocessor.run.<locals>.<genexpr>y   s     /T)3		#)s   #%z)\b)
r   rM   keyssortlenra   compilejoinrF   rK   )r   root	abbr_lists      r   runAbbrTreeprocessor.runq   si    zz*+	3-**vsxx/T)/T'T%VVZ[\$r   )rF   r   )NN)r7   zMarkdown | Noner   zdict | NonerE   )rW   etree.ElementrX   etree.Element | NonereturnNone)rk   ro   rq   rp   )
r:   r;   r<   r=   r>   r   rK   rm   r?   r@   rA   s   @r   r3   r3   Q   s    = 
0
  
 r   r3   c                  ~   ^  \ rS rSrSr\R                  " S\R                  5      rSU 4S jjr	S	S jr
S
S jrSrU =r$ )r6   ~   z(Parse text for abbreviation references. z7^[*]\[(?P<abbr>[^\\]*?)\][ ]?:[ ]*\n?[ ]*(?P<title>.*)$c                0   > X l         [        TU ]	  U5        g rE   )r   r   r   )r   r4   r   r   s      r   r   AbbrBlockprocessor.__init__   s     
 r   c                    g)NTr   )r   rX   blocks      r   testAbbrBlockprocessor.test   s    r   c                   UR                  S5      nU R                  R                  U5      nU(       Ga1  UR                  S5      R	                  5       nUR                  S5      R	                  5       nU(       a  U(       a  US:X  d  US:X  a  U R
                  R                  U5        OX`R
                  U'   X4R                  5       S R	                  5       (       a1  UR                  SX4R                  5       S R                  S5      5        USUR                  5        R	                  5       (       a2  UR                  SUSUR                  5        R                  S5      5        gUR                  SU5        g	)
zu
Find and remove all abbreviation references from the text.
Each reference is added to the abbreviation collection.

r   r-   rI   z''z""N
TF)poprF   searchrO   stripr   rR   rT   lstriprU   rstrip)r   rX   blocksrx   rZ   r-   rI   s          r   rm   AbbrBlockprocessor.run   s    

1GGNN5!776?((*DGGG$**,ED=ETMJJNN4(',JJt$?((**MM!U5578_%;%;D%AB!'')$**,,MM!U:AGGI%6%=%=d%CDar   )r   )r4   r   r   dict)rX   ro   rx   strrq   bool)rX   ro   r   z	list[str]rq   r   )r:   r;   r<   r=   r>   ra   ri   	MULTILINErF   r   ry   rm   r?   r@   rA   s   @r   r6   r6   ~   s2    3	NPRP\P\	]B! r   r6   z4This class has been renamed to `AbbrBlockprocessor`.zJThis class will be removed in the future; use `AbbrTreeprocessor` instead.c                  :   ^  \ rS rSrSrSU 4S jjrSS jrSrU =r$ )AbbrInlineProcessor   zAbbreviation inline pattern. c                0   > [         TU ]  U5        X l        g rE   )r   r   rI   )r   patternrI   r   s      r   r   AbbrInlineProcessor.__init__   s    !
r   c                    [         R                  " S5      n[        UR                  S5      5      Ul        UR                  SU R                  5        X1R                  S5      UR                  S5      4$ )Nr-   rI   r   )	rP   rQ   r
   rO   rL   setrI   rU   rR   )r   rZ   datar-   s       r   handleMatchAbbrInlineProcessor.handleMatch   sQ    }}V$ 1	$**%WWQZq))r   )rI   )r   r   rI   r   )rZ   zre.Match[str]r   r   rq   ztuple[etree.Element, int, int])	r:   r;   r<   r=   r>   r   r   r?   r@   rA   s   @r   r   r      s    (* *r   r   c                     [        S0 U D6$ )Nr   )r   )r   s    r   makeExtensionr      s    "6""r   )r>   
__future__r    r   r5   r   inlinepatternsr   r1   r	   utilr
   r   typingr   ra   xml.etree.ElementTreerP   ElementTreer   blockparsersr   r   r3   r6   AbbrPreprocessorr   r   r   r   r   <module>r      s     #  , , * +   	 % %*'bI 'bT*  * Z% %P TUVhi  XY*/ * Z*#r   