a
    ö£Be¹  ã                   @   s0   d dl Z ddlmZ G dd„ deƒZdd„ ZdS )é    Né   )ÚDirectivePluginc                   @   s   e Zd Zdd„ Zdd„ ZdS )ÚIncludec                 C   sP  |j  d¡}|sdddœS d}|  |¡}|rFt|ƒ}d|v rJ|d }ni }|  |¡}tj tj |¡|¡}	tj 	|	¡}	|	|krŒdd| dœS tj 
|	¡s¦dd| dœS t|	d	ƒ�"}
|
 ¡ }| |¡}W d   ƒ n1 sØ0    Y  tj |¡d
 }|dv �r(| ¡ }|	|j d< | |¡ | |¡ |jS |dv �r<d|dœS |	|d< d||dœS )NÚ__file__Zblock_errorzMissing source file)ÚtypeÚrawzutf-8ÚencodingzCould not include self: zCould not find file: Úrbr   >   z	.markdownz.mkdz.md>   z.htmlz.xhtmlz.htmZ
block_htmlÚfilepathÚinclude)r   r   Úattrs)ÚenvÚgetZparse_optionsÚdictZparse_titleÚosÚpathÚjoinÚdirnameÚnormpathÚisfileÚopenÚreadÚdecodeÚsplitextZ	state_clsÚprocessÚparseÚtokens)ÚselfÚblockÚmÚstateZsource_filer   Úoptionsr   ÚrelpathÚdestÚfÚcontentÚextÚ	new_state© r(   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mistune/directives/include.pyr      sL    



þþ(





ýzInclude.parsec                 C   s2   |  d| j¡ |jr.|jjdkr.|j  dt¡ d S )Nr   Úhtml)Úregisterr   ÚrendererÚNAMEÚrender_html_include)r   Ú	directiveÚmdr(   r(   r)   Ú__call__:   s    zInclude.__call__N)Ú__name__Ú
__module__Ú__qualname__r   r1   r(   r(   r(   r)   r      s   4r   c                 K   s   d| d S )Nz <pre class="directive-include">
z</pre>
r(   )r,   Útextr   r(   r(   r)   r.   @   s    r.   )r   Ú_baser   r   r.   r(   r(   r(   r)   Ú<module>   s   ;