B
    &‹d@  ã               @   s˜   d dl Z ddlmZ ddlmZ dgZde d Ze  de d	 ¡Zd
d„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    Né   )Ú
LINK_LABEL)ÚunikeyÚplugin_footnotesz\[\^(z)\]z( {0,3})\[\^(z0)\]:[ \t]*([^\n]*\n+(?:\1 {1,3}(?! )[^\n]*\n+)*)c             C   sf   t | d¡ƒ}| d¡}|r$||kr2d| d¡fS | dd¡}|d7 }||d< |d  |¡ d||fS )Né   Údef_footnotesÚtextr   Zfootnote_indexÚ	footnotesÚfootnote_ref)r   ÚgroupÚgetÚappend)ÚinlineÚmÚstateÚkeyr   Úindex© r   úf/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/mistune/plugins/footnotes.pyÚparse_inline_footnote   s    
r   c             C   s0   t | d¡ƒ}||d kr,| d¡|d |< d S )Nr   r   é   )r   r   )Úblockr   r   r   r   r   r   Úparse_def_footnote$   s    r   c             C   sº   |d }|| }|  ¡ }d|kr.d|dœg}n|| ¡ }x|dd … D ]
}	|	rDP qDW t|	ƒt|	 ¡ ƒ }
tjdt|
ƒ d tjd}| d	|¡}|  	||¡}t
|tƒsª|g}d
|||fdœS )Nr   Ú
Z	paragraph)Útyper   r   z^ {z,})ÚflagsÚ Úfootnote_item)r   ÚchildrenÚparams)ÚstripÚ
splitlinesÚlenÚlstripÚreÚcompileÚstrÚMÚsubZ
parse_textÚ
isinstanceÚlist)r   ÚkÚir   r   r   Zstripped_textr   ÚlinesZsecond_lineÚspacesÚpatternr   r   r   Úparse_footnote_item*   s$    
r0   c                sP   ˆ  d¡}|s|S ‡ ‡fdd„t|ƒD ƒ}d|dœg}ˆ j |ˆ jˆ¡}|| S )Nr	   c                s$   g | ]\}}t ˆ j||d  ˆƒ‘qS )r   )r0   r   )Ú.0r,   r+   )Úmdr   r   r   ú
<listcomp>K   s   z%md_footnotes_hook.<locals>.<listcomp>)r   r   )r   Ú	enumerater   Úrenderr   )r2   Úresultr   r	   r   ÚtokensÚoutputr   )r2   r   r   Úmd_footnotes_hookE   s    
r9   c             C   s   d| |dœS )Nr
   )r   r   r   r   )r   r   r   r   r   Úrender_ast_footnote_refS   s    r:   c             C   s   d| ||dœS )Nr   )r   r   r   r   r   )r   r   r   r   r   r   Úrender_ast_footnote_itemW   s    r;   c             C   s,   t |ƒ}d| d }|d | d | d S )Nz$<sup class="footnote-ref" id="fnref-z">z<a href="#fn-z
</a></sup>)r&   )r   r   r,   Úhtmlr   r   r   Úrender_html_footnote_ref`   s    r=   c             C   s   d|  d S )Nz!<section class="footnotes">
<ol>
z</ol>
</section>
r   )r   r   r   r   Úrender_html_footnotesf   s    r>   c             C   sX   t |ƒ}d| d }|  ¡ } |  d¡r<| d d… | d } n| | } d| d |  d S )Nz<a href="#fnref-z" class="footnote">&#8617;</a>z</p>éüÿÿÿz<li id="fn-z">z</li>
)r&   ÚrstripÚendswith)r   r   r   r,   Úbackr   r   r   Úrender_html_footnote_itemn   s    
rC   c             C   sü   | j  dtt¡ | j j d¡}|dkr8| j j |d¡ n| j j d¡ | j dt	t
¡ | jj d¡}|dkr~| jj |d¡ n| jj d¡ | jjdkrÄ| j dt¡ | j dt¡ | j d	t¡ n(| jjd
krì| j dt¡ | j dt¡ | j t¡ d S )NZfootnoteZstd_linkéÿÿÿÿZdef_footnoteZdef_linkr<   r
   r   r	   Úast)r   Zregister_ruleÚINLINE_FOOTNOTE_PATTERNr   Úrulesr   Úinsertr   r   ÚDEF_FOOTNOTEr   ÚrendererÚNAMEÚregisterr=   rC   r>   r:   r;   Zafter_render_hooksr9   )r2   r   r   r   r   r   z   s*    )r$   Zinline_parserr   Úutilr   Ú__all__rF   r%   rI   r   r   r0   r9   r:   r;   r=   r>   rC   r   r   r   r   r   Ú<module>   s    	