
    /Vh                        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	erdd	l
mZ d
 Zd Zd Zd Z e	j                   defdefdefdefdg      ZddZddZddZ G d de      Z G d de      Zd Zy)z
Adds attribute list syntax to Python-Markdown.
Inspired by
[Maruku](http://maruku.rubyforge.org/proposal.html#attribute_lists)'s
feature of the same name.

See the [documentation](https://Python-Markdown.github.io/extensions/attr_list)
for details.
    )annotations)TYPE_CHECKING   )	Extension   )TreeprocessorN)Elementc                R    |j                  dd      \  }}||j                  d      fS )N=r   "splitstripstkvs       M/home/dcms/DCMS/lib/python3.12/site-packages/markdown/extensions/attr_list.py_handle_double_quoter   &   '    773?DAqaggcl?    c                R    |j                  dd      \  }}||j                  d      fS )Nr   r   'r   r   s       r   _handle_single_quoter   +   r   r   c                &    |j                  dd      S )Nr   r   )r   r   r   s     r   _handle_key_valuer   0   s    773?r   c                j    |j                  d      rd|dd  fS |j                  d      rd|dd  fS ||fS )N.r   #id)
startswithr   s     r   _handle_wordr$   4   sC    ||CAabEz||CQqrU{a4Kr   z[^ =}]+=".*?"z[^ =}]+='.*?'z[^ =}]+=[^ =}]+z[^ =}]+) Nc                t    t         j                  |       \  }}|j                  d      }|dk7  r||d nd}||fS )z Parse attribute list and return a list of attribute tuples.

    Additionally, return any text that remained after a curly brace. In typical cases, its presence
    should mean that the input does not match the intended attribute list syntax.
    }N )_scannerscanfind)attrs_stringattrs	remainderindexs       r   get_attrs_and_remainderr1   E   sD      }}\2E9NN3E%*b[	%&!bI)r   c                    t        |       d   S )z4 Soft-deprecated. Prefer `get_attrs_and_remainder`. r   )r1   )strs    r   	get_attrsr4   R   s    "3'**r   c                    | j                   dv S )N)h1h2h3h4h5h6)tag)elems    r   isheaderr>   W   s    88;;;r   c                     e Zd ZdZ ej
                  dj                  e            Z ej
                  dj                  e            Z ej
                  dj                  e            Z	 ej
                  d      Z
ddZdddd	Zdd
Zy)AttrListTreeprocessorz\{\:?[ ]*([^\}\n ][^\n]*)[ ]*\}z[ ]+{}[ ]*$z\n[ ]*{}[ ]*$z^{}z[^A-Z_a-z\u00c0-\u00d6\u00d8-\u00f6\u00f8-\u02ff\u0370-\u037d\u037f-\u1fff\u200c-\u200d\u2070-\u218f\u2c00-\u2fef\u3001-\ud7ff\uf900-\ufdcf\ufdf0-\ufffd\:\-\.0-9\u00b7\u0300-\u036f\u203f-\u2040]+c                l   |j                         D ]   }| j                  j                  |j                        rz| j                  }t        |      s|j                  dv r| j                  }t        |      r|j                  dk(  rd }t        |      D ]  \  }}|j                  dv s|} n |~|d   j                  ro|j                  |d   j                        }|s| j                  ||j                  d      d      r|d   j                  d |j                          |d   _	        ||dkD  r||dz
     j                  rz|j                  ||dz
     j                        }|s\| j                  ||j                  d      d      r||dz
     j                  d |j                          ||dz
     _	        |j                  s|j                  |j                        }|s| j                  ||j                  d      d      r|j                  d |j                          |_        't        |      r|d   j                  r|j                  |d   j                        }|sc| j                  ||j                  d      d      r|d   j                  d |j                          |d   _	        t        |      s|d   j                  j                  d	      j                         |d   _	        |j                  s|j                  |j                        }|s | j                  ||j                  d      d      rE|j                  d |j                          |_        t        |      st|j                  j                  d	      j                         |_        |j                  s| j                   j#                  |j                        }|s| j                  ||j                  d            }|j                  |j%                         d  |z   |_	        # y )
N)dttdthli)ulolr(   r   Tstrictr   r!   )itermdis_block_levelr<   BLOCK_REr>   	HEADER_RElen	enumeratetailsearchassign_attrsgroupstarttextrstrip	INLINE_REmatchend)	selfdocr=   REposichildmr/   s	            r   runzAttrListTreeprocessor.rung   s8   HHJ 9	DDww%%dhh/]]D>TXX1C%CBt9T!1C$-dO "5 994"#C!" {tBx}}IId2hmm4#'#4#4T1771:d#4#S04Rjqwwy0IRS1Wc!e9I9IIId3q5k&6&67#'#4#4T1771:d#4#S37A;3C3CJQWWY3OSU 0IIdii0#'#4#4T1771:d#4#S,0IIjqwwy,A	Y48==		$r(--0A#00qwwqz$0O,0HMM*1779,EDHM'~04R0D0DS0I0P0P0RRYY		$)),A#00qwwqz$0O(,		*1779(=DI'~,0II,<,<S,A,H,H,J	 99,,TYY7A$($5$5dAGGAJ$G	$(IIaeegh$7)$C	s9	Dr   FrH   c                   t        |      \  }}|r|r|S |D ]t  \  }}|dk(  rI|j                  d      }|r#|j                  ddj                  ||             A|j                  d|       T|j                  | j	                  |      |       v |S )z Assign `attrs` to element.

        If the `attrs_string` has an extra closing curly brace, the remaining text is returned.

        The `strict` argument controls whether to still assign `attrs` if there is a remaining `}`.
        r    classz{} {})r1   getsetformatsanitize_name)	r[   r=   r-   rI   r.   r/   r   r   clss	            r   rS   z"AttrListTreeprocessor.assign_attrs   s     3<@yi 
	3DAqCxhhw'HHWgnnS!&<=HHWa( ++A.2
	3 r   c                :    | j                   j                  d|      S )z~
        Sanitize name as 'an XML Name, minus the `:`.'
        See <https://www.w3.org/TR/REC-xml-names/#NT-NCName>.
        _)NAME_REsub)r[   names     r   rh   z#AttrListTreeprocessor.sanitize_name   s    
 ||T**r   N)r\   r	   returnNone)r=   r	   r-   r3   rI   boolro   r3   )rn   r3   ro   r3   )__name__
__module____qualname__BASE_RErecompilerg   rN   rM   rX   rl   rb   rS   rh    r   r   r@   r@   [   s    0G

>009:Irzz*11':;H

6==12Ibjj H IG:Dx PU 2+r   r@   c                      e Zd ZdZd Zy)AttrListExtensionz. Attribute List extension for Python-Markdown c                r    |j                   j                  t        |      dd       |j                  |        y )N	attr_list   )treeprocessorsregisterr@   registerExtension)r[   rK   s     r   extendMarkdownz AttrListExtension.extendMarkdown   s.    
""#8#<k1M
T"r   N)rr   rs   rt   __doc__r   rx   r   r   rz   rz      s
    8#r   rz   c                     t        di | S )Nrx   )rz   )kwargss    r   makeExtensionr      s    &v&&r   )r-   r3   ro   z!tuple[list[tuple[str, str]], str])r3   r3   ro   zlist[tuple[str, str]])r=   r	   ro   rq   )r   
__future__r   typingr   r)   r   r~   r   rv   xml.etree.ElementTreer	   r   r   r   r$   Scannerr*   r1   r4   r>   r@   rz   r   rx   r   r   <module>r      s   " #    * 	-

 2::+,+,*+ 
+
<f+M f+R#	 #'r   