U
    /e                     @  s   d Z ddlmZ ddlZee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
ZG dd de
je
jZG dd deZdd ZdS )a   Display code blocks in collapsible sections when outputting to HTML.

This directive takes a heading to use for the collapsible code block:

.. code-block:: rest

    .. collapsible-code-block:: python
        :heading: Some Code

                print("Hello, Bokeh!")

This directive is identical to the standard ``code-block`` directive
that Sphinx supplies, with the addition of one new option:

heading (string):
    A heading to put for the collapsible block. Clicking the heading
    expands or collapses the block.



Examples
--------

The inline example code above produces the following output:

.. collapsible-code-block:: python
    :heading: Some Code

        print("Hello, Bokeh!")

    )annotationsN)basename)nodes)	unchanged)	CodeBlock   )PARALLEL_SAFE)collapsible_code_blockCollapsibleCodeBlocksetupc                   @  s0   e Zd Zedd Zedd ZejejfZdS )r	   c                 C  s    |d }| j d| d d S )Nheadingz<details><summary>z
</summary>bodyappend)visitornoder    r   J/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sphinxext/collapsible_code_block.py
visit_htmlT   s    z!collapsible_code_block.visit_htmlc                 C  s   | j d d S )Nz
</details>r   )r   _noder   r   r   depart_htmlY   s    z"collapsible_code_block.depart_htmlN)__name__
__module____qualname__staticmethodr   r   __func__htmlr   r   r   r   r	   R   s
   

r	   c                   @  s&   e Zd ZejZejed dd ZdS )r
   )r   c                 C  s   | j jjd }t|}| jd}| d| dd}tjdd|gd}t	|| j
dd	d
}t| }||d  |j|d  ||gS )NsourceZccbz.ccb-.- )idsr   ZCode)	target_idr   r   )Zstate_machiner   documentr   envZnew_serialnoreplacer   targetr	   optionsgetr   runZsetup_childchildrenr   )selfZ
rst_sourceZrst_filenameZ	serial_nor"   r&   blockcbr   r   r   r)   e   s    
zCollapsibleCodeBlock.runN)r   r   r   r   Zoption_specupdater   r)   r   r   r   r   r
   `   s   r
   c                 C  s    | j ttjd | dt tS )z+ Required Sphinx extension setup function. )r   zcollapsible-code-block)add_noder	   r   Zadd_directiver
   r   )Zappr   r   r   r   v   s    r   )__doc__
__future__r   logging	getLoggerr   logos.pathr   Zdocutilsr   Zdocutils.parsers.rst.directivesr   Zsphinx.directives.coder   r    r   __all__ZGeneralElementr	   r
   r   r   r   r   r   <module>   s   #
