B
    &dx                 @   sH   d dl Z d dlmZ ddlmZ G dd deZdddZdd	d
ZdS )    N)
preprocess   )	Directivec               @   s   e Zd Zdd Zdd ZdS )DirectiveIncludec          	   C   s  | d}|sdddS |d}| |}tjtj||}tj|}||krddd| dS tj|s~dd| dS t	|d}|
 }	|	d	}
W d Q R X |stj|d
 }|dkrt|
d|i\}
}||
|S |dkrd|
dS d|
|||fdS )N__file__Zblock_errorz!Missing source file configuration)typerawvaluezCould not include self: zCould not find file: rbzutf-8r   >   .mkd.md	.markdown>   .xhtml.html.htmZ
block_html)r   textinclude)r   r   params)getgroupZparse_optionsospathjoindirnamenormpathisfileopenreaddecodesplitextr   parse)selfblockmstateZsource_filerelpathoptionsdestfcontentr   ext r+   g/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/mistune/directives/include.pyr       s6    



zDirectiveInclude.parsec             C   sF   |  |d |jjdkr(|jdt n|jjdkrB|jdt d S )Nr   htmlast)Zregister_directiverendererNAMEregisterrender_html_includerender_ast_include)r!   mdr+   r+   r,   __call__2   s
    zDirectiveInclude.__call__N)__name__
__module____qualname__r    r5   r+   r+   r+   r,   r      s   +r   c             C   s   d| |||dS )Nr   )r   r   r%   abspathr&   r+   )r   r%   r9   r&   r+   r+   r,   r3   ;   s
    r3   c             C   s   d}|| d |  d S )Nz1<section class="directive-include" data-relpath="z">
z</section>
r+   )r   r%   r9   r&   r-   r+   r+   r,   r2   E   s    r2   )NN)NN)r   Zmistune.markdownr   baser   r   r3   r2   r+   r+   r+   r,   <module>   s
   5

