o
    tfV                     @   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type
blank_line   )envgetgroupstripappend_tokenend)blockmstaterefkeytext r   ]/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/mistune/plugins/abbr.pyparse_ref_abbr   s   


r   c                 C   s`  |j d}|s|d|dS |jr)|jd }|d dkr)|j  |d | }|j d}|sEtdd	d
 | D }||j d< d}|t	|k r|
||}|sVn6| }||krl||| }	|d|	d |d}
|dd|
dgd||
 id | }|t	|k sM|dkr|d|d d S |t	|k r|d||d  d d S 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   end_posholelabelr   r   r   process_text   sD   





r3   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   r5   c                 C   sR   | j jdttdd tt| j| j_| jr%| jj	dkr'| jdt
 dS dS 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
MethodTyper3   r-   r4   NAMEr5   )mdr   r   r   r   L   s
   )r   r:   utilr   helpersr   __all__r9   r   r3   r5   r   r   r   r   r   <module>   s    
*