a
    ö£Be÷  ã                   @   sB   d dl mZ ddlmZ ddlmZ ddlmZ G dd„ dƒZdS )	é    )ÚOptionalé   )Ú
BlockState)ÚBlockParser)ÚInlineParserc                   @   sv   e Zd ZdZdee ee dœdd„Zdd„ Ze	dœd	d
„Z
dd„ Zdeee	 dœdd„Zddd„Zedœdd„ZdS )ÚMarkdowna½  Markdown instance to convert markdown text into HTML or other formats.
    Here is an example with the HTMLRenderer::

        from mistune import HTMLRenderer

        md = Markdown(renderer=HTMLRenderer(escape=False))
        md('hello **world**')

    :param renderer: a renderer to convert parsed tokens
    :param block: block level syntax parser
    :param inline: inline level syntax parser
    :param plugins: mistune plugins to use
    N)ÚblockÚinlinec                 C   sZ   |d u rt ƒ }|d u rtƒ }|| _|| _|| _g | _g | _g | _|rV|D ]}|| ƒ qHd S ©N)r   r   Úrendererr   r	   Úbefore_parse_hooksÚbefore_render_hooksÚafter_render_hooks)Úselfr   r   r	   ÚpluginsÚplugin© r   úS/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mistune/markdown.pyÚ__init__   s    zMarkdown.__init__c                 C   s   || ƒ d S r
   r   )r   r   r   r   r   Úuse*   s    zMarkdown.use)Ústatec                 C   s(   |   |j|¡}| jr |  ||¡S t|ƒS r
   )Ú_iter_renderÚtokensr   Úlist)r   r   Údatar   r   r   Úrender_state-   s    zMarkdown.render_statec                 c   sd   |D ]Z}d|v r.|   |d |¡}t|ƒ|d< n*d|v rX| d¡}|  | d¡|j¡|d< |V  qd S )NÚchildrenÚtextz 
	)r   r   Úpopr	   ÚstripÚenv)r   r   r   Útokr   r   r   r   r   r   3   s    
zMarkdown._iter_render)Úsr   c                 C   s¨   |du r| j  ¡ }| dd¡}| dd¡}| d¡s<|d7 }| |¡ | jD ]}|| |ƒ qL| j  |¡ | jD ]}|| |ƒ qn|  |¡}| j	D ]}|| ||ƒ}qŽ||fS )zúParse and convert the given markdown string. If renderer is None,
        the returned **result** will be parsed markdown tokens.

        :param s: markdown string
        :param state: instance of BlockState
        :returns: result, state
        Nz
Ú
ú)
r   Ú	state_clsÚreplaceÚendswithÚprocessr   Úparser   r   r   )r   r"   r   ÚhookÚresultr   r   r   r)   ?   s     






zMarkdown.parseúutf-8c                 C   sd   |d u r| j  ¡ }||jd< t|dƒ�}| ¡ }W d   ƒ n1 sD0    Y  | |¡}|  ||¡S )NÚ__file__Úrb)r   r%   r    ÚopenÚreadÚdecoder)   )r   ÚfilepathÚencodingr   Úfr"   r   r   r   r0   `   s    

&
zMarkdown.read)r"   c                 C   s   |d u rd}|   |¡d S )Nr#   r   )r)   )r   r"   r   r   r   Ú__call__k   s    zMarkdown.__call__)NNNN)N)r,   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   Ústrr)   r0   r5   r   r   r   r   r      s       ýþ!
r   N)	Útypingr   Úcorer   Zblock_parserr   Zinline_parserr   r   r   r   r   r   Ú<module>   s   