o
    N¾±hƒ  ã                   @   sF   d dl m Z  d dlZd dlZd dlZdejj_dd„ Zdd„ ZdZ	dS )	é    )ÚglobNÚsphinx_gallery_pngc                 K   sÄ   t j |d ¡}ttt j |d¡ƒƒ}ttt j |d¡ƒƒ}|d }tƒ }tƒ }	t||ƒD ]-\}
}||	vrZ|	t|ƒO }	t	|ƒ}t j 
|¡d d }| |¡ t ||¡ t |
|¡ q-t||d ƒS )a<  Scrape Plotly figures for galleries of examples using
    sphinx-gallery.

    Examples should use ``plotly.io.show()`` to display the figure with
    the custom sphinx_gallery renderer.

    Since the sphinx_gallery renderer generates both html and static png
    files, we simply crawl these files and give them the appropriate path.

    Parameters
    ----------
    block : tuple
        A tuple containing the (label, content, line_number) of the block.
    block_vars : dict
        Dict of block variables.
    gallery_conf : dict
        Contains the configuration of Sphinx-Gallery
    **kwargs : dict
        Additional keyword arguments to pass to
        :meth:`~matplotlib.figure.Figure.savefig`, e.g. ``format='svg'``.
        The ``format`` kwarg in particular is used to set the file extension
        of the output file (currently only 'png' and 'svg' are supported).

    Returns
    -------
    rst : str
        The ReSTructuredText that will be rendered to HTML containing
        the images.

    Notes
    -----
    Add this function to the image scrapers
    Úsrc_filez*.pngz*.htmlÚimage_path_iteratorr   z.htmlÚsrc_dir)ÚosÚpathÚdirnameÚsortedr   ÚjoinÚlistÚsetÚzipÚnextÚsplitextÚappendÚshutilÚmoveÚ
figure_rst)ÚblockÚ
block_varsÚgallery_confÚkwargsÚexamples_dirÚpngsÚhtmlsr   Úimage_namesÚseenÚhtmlÚpngÚthis_image_path_pngÚthis_image_path_html© r"   úV/var/www/html/Persson_Maskin/env/lib/python3.10/site-packages/plotly/io/_sg_scraper.pyÚplotly_sg_scraper   s    "
€r$   c                    sH   ‡ fdd„| D ƒ}d}|s|S |d }t j dt j |¡¡}t| }|S )aÀ  Generate RST for a list of PNG filenames.

    Depending on whether we have one or more figures, we use a
    single rst call to 'image' or a horizontal list.

    Parameters
    ----------
    figure_list : list
        List of strings of the figures' absolute paths.
    sources_dir : str
        absolute path of Sphinx documentation sources

    Returns
    -------
    images_rst : str
        rst code to embed the images in the document
    c                    s*   g | ]}t j |ˆ ¡ t jd ¡ d ¡‘qS )ú/)r   r   ÚrelpathÚreplaceÚsepÚlstrip)Ú.0Úfigure_path©Úsources_dirr"   r#   Ú
<listcomp>T   s    ÿÿzfigure_rst.<locals>.<listcomp>Ú r   Úimages)r   r   r   ÚbasenameÚSINGLE_HTML)Úfigure_listr-   Úfigure_pathsÚ
images_rstÚfigure_namer+   r"   r,   r#   r   A   s   
þr   z
.. raw:: html
    :file: %s
)
r   r   r   ÚplotlyÚioÚ	renderersÚdefaultr$   r   r2   r"   r"   r"   r#   Ú<module>   s   
4 