
    ̆h                    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     P/opt/services/DDDS/venv/lib/python3.13/site-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                  V   ^  \ rS rSrSrSS	U 4S jjjrS
S 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                d    [         R                  " SSU05      n[        U5      Ul        X4l        U$ )zCreate an `abbr` element. r-   title)etreeElementr
   texttail)r   rI   rL   rM   r-   s        r   create_element AbbrTreeprocessor.create_elementY   s-    }}Vgu%56 &		r   c                @   [        U5       H  nU R                  X15        M     UR                  =n(       a  [        U[        5      (       d  [        [        U R                  R                  U5      5      5       H  nU R                  UR                  S5         (       d  M(  U R                  U R                  UR                  S5         UR                  S5      XER                  5       S 5      nUR                  SU5        USUR                  5        nM     XAl        Ub  UR                  (       a  UR                  n[        U5      R                  U5      S-   n[        U[        5      (       d  [        [        U R                  R                  U5      5      5       Hu  nU R                  U R                  UR                  S5         UR                  S5      XuR                  5       S 5      nUR                  X5        USUR                  5        nMw     Xql        gggg)zVRecursively iterate over elements, run regex on text and wrap matches in `abbr` tags. r   Nr   )reversediter_elementrL   
isinstancer
   listrF   finditerr   grouprN   endinsertstartrM   index)	r   elparentchildrL   mr-   rM   rZ   s	            r   rR   AbbrTreeprocessor.iter_element`   s   b\Ee( "77?4?dL11!$tww'7'7'=">?Azz!''!*--#224::aggaj3I177ST:W[\a\a\c\dWef		!T*#JQWWY/	 @
 "''77DL&&r*Q.EdL11!$tww'7'7'=">?A..tzz!''!*/EqwwqzSWX]X]X_X`SabDMM%.
+D @  2 #*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).0ra   s     r   	<genexpr>(AbbrTreeprocessor.run.<locals>.<genexpr>~   s     /T)3		#)s   #%z)\b)
r   rT   keyssortlenre   compilejoinrF   rR   )r   root	abbr_lists      r   runAbbrTreeprocessor.runv   si    zz*+	3-**vsxx/T)/T'T%VVZ[\$r   )rF   r   )NN)r7   zMarkdown | Noner   zdict | None)rI   strrL   rs   rM   rs   returnetree.ElementrE   )r[   ru   r\   etree.Element | Nonert   None)ro   ru   rt   rv   )r:   r;   r<   r=   r>   r   rN   rR   rq   r?   r@   rA   s   @r   r3   r3   Q   s$    = 
,
  
 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   r\   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   searchrV   stripr   rW   rX   lstriprY   rstrip)r   r\   blocksr}   r^   r-   rI   s          r   rq   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)r\   ru   r}   rs   rt   bool)r\   ru   r   z	list[str]rt   r   )r:   r;   r<   r=   r>   re   rm   	MULTILINErF   r   r~   rq   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   )	rJ   rK   r
   rV   rL   setrI   rY   rW   )r   r^   datar-   s       r   handleMatchAbbrInlineProcessor.handleMatch   sQ    }}V$ 1	$**%WWQZq))r   )rI   )r   rs   rI   rs   )r^   zre.Match[str]r   rs   rt   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   re   xml.etree.ElementTreerJ   ElementTreer   blockparserr   r   r3   r6   AbbrPreprocessorr   r   r   r   r   <module>r      s     #  , , * +   	 % %)'bI 'bT/  / d% %P TUVhi  XY*/ * Z*#r   