a
    ö£BeH  ã                   @   sÚ   d dl Z d dlmZ d dlmZ e jde jd�Zd$edœdd	„Z	d%eedœdd„Z
d&eedœdd„Zedœdd„Zedœdd„Zedœdd„Ze  d¡Zedœdd„Ze  d¡Zedœdd„Ze  d ¡Zed!œd"d#„ZdS )'é    N)Úquote)Ú_replace_charrefz^( {0,3})\t)Úflagsé   )Útextc                    s   ‡ fdd„}t  || ¡S )Nc                    s   |   d¡}|dˆ t|ƒ   S )Né   ú )ÚgroupÚlen)ÚmÚs©Úwidth© úO/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mistune/util.pyÚrepl
   s    
z expand_leading_tab.<locals>.repl©Ú_expand_tab_reÚsub)r   r   r   r   r   r   Úexpand_leading_tab	   s    r   ú    )r   Úspacec                 C   s   d| }t  || ¡S )Nz\1r   )r   r   r   r   r   r   Ú
expand_tab   s    r   T©r   r   c                 C   s8   |   dd¡} |   dd¡} |   dd¡} |r4|   dd¡} | S )	zXEscape characters of ``&<>``. If quote=True, ``"`` will be
    converted to ``&quote;``.ú&z&amp;ú<z&lt;ú>z&gt;ú"z&quot;)Úreplacer   r   r   r   Úescape   s    r   )Úlinkc                 C   s   d}t tt| ƒ|d�ƒS )zEscape URL for safety.z:/?#@!$&()*+,;=%)Úsafe)r   r   Úunescape)r    r!   r   r   r   Ú
escape_url    s    ÿr#   ©r   c                 C   s   t t| ƒƒS )zEscape characters for safety.)r   r"   r$   r   r   r   Úsafe_entity*   s    r%   c                 C   s   d  |  ¡ ¡ ¡ }| ¡  ¡ S )z.Generate a unique key for links and footnotes.r   )ÚjoinÚsplitÚstripÚlowerÚupper)r   Úkeyr   r   r   Úunikey/   s    r,   z8&(#[0-9]{1,7};|#[xX][0-9a-fA-F]+;|[^\t\n\f <&#;]{1,32};)c                 C   s   d| vr| S t  t| ¡S )z�
    Copy from `html.unescape`, but `_charref` is different. CommonMark
    does not accept entity references without a trailing semicolon
    r   )Ú_charref_rer   r   r$   r   r   r   r"   <   s    r"   z(<!--.*?-->|<[^>]*>)c                 C   s   t  d| ¡S )NÚ )Ú_striptags_rer   r$   r   r   r   Ú	striptagsI   s    r0   z\n\s+$©Úsrcc                 C   s   t  d| ¡S )NÚ
)Ú_strip_end_rer   r1   r   r   r   Ú	strip_endP   s    r5   )r   )r   )T)ÚreÚurllib.parser   Úhtmlr   ÚcompileÚMr   Ústrr   r   Úboolr   r#   r%   r,   r-   r"   r/   r0   r4   r5   r   r   r   r   Ú<module>   s"   
ÿ


