a
    ö£BeV  ã                   @   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   úW/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/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¡}|sŠt 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   Úrawéÿÿÿÿr   r   Úabbrs_reú|c                 s   s   | ]}t  |¡V  qd S )N)Úrer   )Ú.0Úkr   r   r   Ú	<genexpr>)   ó    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   s@    





ý

r4   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    r6   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Ú
MethodTyper4   r.   r5   ÚNAMEr6   )Úmdr   r   r   r   L   s    )r   r;   Úutilr   Úhelpersr   Ú__all__r:   r   r4   r6   r   r   r   r   r   Ú<module>   s   
ÿ*