B
     d                 @   s`  d dl Z d dlmZ d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ d dlmZ d	d
lmZ d	dlmZmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlmZ d	dlm Z  d	dl!m"Z"m#Z# d	dl$m%Z% eddddZ&edddZ'ee
dddZ(ej)dddZ*ej)dd d!Z+ej,dd"d#d$Z-G d%d& d&eZ.G d'd( d(eZ/dS ))    N)Path)nodes)
directives)Sphinx)BuildEnvironment)SphinxTransform)SphinxDirective   )compiled)findall	read_text)setup_article_info)setup_badges_and_buttons)setup_cards)setup_dropdown)setup_grids)setup_icons)PassthroughTextElementcreate_component)
setup_tabs)appreturnc             C   s   |  dt |  dt | jtjdttfd | jtt	t	ft	t	ft	t	ft	t	ft	t	fd | j
dtdd | t t|  t|  t|  t|  t|  t|  t|  dS )	zSet up the sphinx extension.zbuilder-initedzenv-updatedT)overridehtml)r   latextextmanZtexinfodiv)r   N)connectupdate_css_jsupdate_css_linksadd_noder   	containervisit_containerdepart_containerr   visit_depart_nullZadd_directiveDivZadd_transformAddFirstTitleCssr   r   r   r   r   r   r   )r    r(   d/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/sphinx_design/extension.pysetup_extension   s*    
r*   )r   c             C   s   d| j _t| jd  }| }|jdd | jj	t
| |d }| |j | spttd}|| ttd}t|d }|d	| d
 }| |j | rdS |rd| j _x|dD ]}|  qW |j|dd dS )z$Copy the CSS to the build directory.FZ_sphinx_design_staticT)exist_okzdesign-tabs.jsz
sd_tabs.jszstyle.min.cssutf8zdesign-style.z.min.cssNz*.css)encoding)envsphinx_design_css_changedr   ZoutdirabsoluteexistsmkdirconfigZhtml_static_pathappendstrZadd_js_filenamer   static_module
write_texthashlibmd5encode	hexdigestZadd_css_fileglobunlink)r   Zstatic_pathZstatic_existedZjs_pathcontenthashZcss_pathpathr(   r(   r)   r   5   s*    


r   )r   r.   c             C   s   |j rt|j S dS )zUIf CSS has changed, all files must be re-written, to include the correct stylesheets.N)r/   listZall_docskeys)r   r.   r(   r(   r)   r    S   s    r    )nodec             C   sP   d}i }| ddrd}d|kr,|d |d< | j| j|dfd|i| d S )Nzdocutils containerZis_divFdocutilsstyler   ZCLASS)getbodyr4   Zstarttag)selfrD   classesattrsr(   r(   r)   r#   Y   s    r#   c             C   s   | j d d S )Nz</div>
)rH   r4   )rI   rD   r(   r(   r)   r$   d   s    r$   )rD   r   c             C   s   dS )zvisit/depart passthroughNr(   )rI   rD   r(   r(   r)   r%   h   s    r%   c               @   s2   e Zd ZdZdZdZejejdZdZ	dd Z
dS )r&   zSame as the ``container`` directive,
    but does not add the ``container`` class in HTML outputs,
    which can interfere with Bootstrap CSS.
    r	   T)rF   r6   c          	   C   s   y | j rt| j d }ng }W n. tk
rN   | d| j| j d f Y nX tdd| j|d}d| j	kr~| j	d |d< | 
| | | | jr| j| j| j| |gS )Nr   z7Invalid class attribute value for "%s" directive: "%s".r   
)ZrawtextrJ   rF   )	argumentsr   Zclass_option
ValueErrorerrorr6   r   joinr?   optionsZset_source_infoZadd_namestateZnested_parseZcontent_offset)rI   rJ   rD   r(   r(   r)   runw   s     


zDiv.runN)__name__
__module____qualname____doc__Zoptional_argumentsZfinal_argument_whitespacer   Z	unchangedZoption_specZhas_contentrS   r(   r(   r(   r)   r&   l   s   r&   c               @   s   e Zd ZdZdZdd ZdS )r'   z/Add a CSS class to to the first sections title.i  c             C   s   d}xDt | jtjD ]0}x(t |tjD ]}| dkr*d}P q*W P qW |sRd S x`t | jtjD ]L}t|jd tj	rd|jd kr|jd d 
d ndg|jd d< P qdW d S )NFZsd_hide_titleTr   rJ   z	sd-d-none)r   Zdocumentr   docinfo
field_nameZastextsection
isinstancechildrentitler4   )rI   ZhiderX   r6   rZ   r(   r(   r)   apply   s    zAddFirstTitleCss.applyN)rT   rU   rV   rW   Zdefault_priorityr^   r(   r(   r(   r)   r'      s   r'   )0r9   pathlibr   rE   r   Zdocutils.parsers.rstr   Zsphinx.applicationr   Zsphinx.environmentr   Zsphinx.transformsr   Zsphinx.util.docutilsr    r
   r7   _compatr   r   Zarticle_infor   Zbadges_buttonsr   Zcardsr   Zdropdownr   Zgridsr   Ziconsr   Zsharedr   r   tabsr   r*   r   r    Noder#   r$   ZElementr%   r&   r'   r(   r(   r(   r)   <module>   s2    