U
    mufV                     @   s^   d dl Z d dlZddlmZ ddlmZ dgZde d Zdd	 Zd
d Z	dd Z
dd ZdS )    N   escape)PREVENT_BACKSLASHabbrz^ {0,3}\*\[(?P<abbr_key>[^\]]+)z<\]:(?P<abbr_text>(?:[ \t]*\n(?: {3,}|\t)[^\n]+)|(?:[^\n]*))$c                 C   sX   |j d}|si }|d}|d}| ||< ||j d< |ddi | d S )N	ref_abbrsZabbr_keyZ	abbr_texttypeZ
blank_line   )envgetgroupstripappend_tokenend)blockmstaterefkeytext r   8/tmp/pip-unpacked-wheel-8p1ovdot/mistune/plugins/abbr.pyparse_ref_abbr   s    


r   c                 C   sX  |j d}|s |d|dS |jrR|jd }|d dkrR|j  |d | }|j d}|stdd	d
 | D }||j d< d}|t	|k r|
||}|sq| }||kr||| }	|d|	d |d}
|dd|
dgd||
 id | }q|dkr.|d|d n&|t	|k rT|d||d  d d S )Nr   r   )r   rawr   r   abbrs_re|c                 s   s   | ]}t |V  qd S )N)rer   ).0kr   r   r   	<genexpr>)   s     zprocess_text.<locals>.<genexpr>r   r   title)r   childrenattrs)r
   r   r   tokenspopr   compilejoinkeyslensearchstartr   r   )inliner   r   r   lastr   posr   Zend_posZholelabelr   r   r   process_text   s@    







r0   c                 C   s(   |sd| d S dt | d | d S )Nz<abbr>z</abbr>z<abbr title="z">r   )rendererr   r!   r   r   r   render_abbrF   s    r2   c                 C   sJ   | j jdttdd tt| j| j_| jrF| jj	dkrF| jdt
 dS )aG  A mistune plugin to support abbreviations, spec defined at
    https://michelf.ca/projects/php-markdown/extra/#abbr

    Here is an example:

    .. code-block:: text

        The HTML specification
        is maintained by the W3C.

        *[HTML]: Hyper Text Markup Language
        *[W3C]:  World Wide Web Consortium

    It will be converted into HTML:

    .. code-block:: html

        The <abbr title="Hyper Text Markup Language">HTML</abbr> specification
        is maintained by the <abbr title="World Wide Web Consortium">W3C</abbr>.

    :param md: Markdown instance
    Zref_abbrZ	paragraph)beforehtmlr   N)r   registerREF_ABBRr   types
MethodTyper0   r,   r1   NAMEr2   )Zmdr   r   r   r   L   s    )r   r7   utilr   Zhelpersr   __all__r6   r   r0   r2   r   r   r   r   r   <module>   s   
*