U
    mufH                     @   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 0/tmp/pip-unpacked-wheel-8p1ovdot/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| k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"   



