o
    tf                     @   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                   @   s   e Zd ZdZ				ddee dee fddZdd Zd	e	fd
dZ
dd Zdded	ee	 fddZdddZdef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   s^   |d u rt  }|d u rt }|| _|| _|| _g | _g | _g | _|r+|D ]}||  q$d S d S N)r   r   rendererr   r	   before_parse_hooksbefore_render_hooksafter_render_hooks)selfr   r   r	   pluginsplugin r   Y/var/www/html/software/conda/envs/catlas/lib/python3.10/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   sf    |D ]-}d|v r|  |d |}t||d< nd|v r-|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sc                 C   s   |du r	| j  }|dd}|dd}|ds|d7 }|| | jD ]}|| | q&| j | | jD ]}|| | q7| |}| j	D ]}|| ||}qG||fS )zParse 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 s"w   Y  ||}| ||S )N__file__rb)r   r%   r    openreaddecoder)   )r   filepathencodingr   fr"   r   r   r   r0   `   s   



zMarkdown.readc                 C   s   |d u rd}|  |d S )Nr#   r   )r)   )r   r"   r   r   r   __call__k   s   zMarkdown.__call__)NNNNr
   )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
    