
    G@d'              	          d Z ddlZddlZddlmZ ddlZddlZddl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ZddlmZ ddlmZmZmZ dd	lmZ  ed
          Z ej        edd          Z ej        edd          Z ej        edd          Z ej        ed          Z  ed ej        dde d          d          Z! ed ej        dde           d          Z"d Z#efdZ$efdZ%efdZ&ddddddefdZ'd!dZ(d  Z)dS )"ad  
Process docstrings with Sphinx.

**AUTHORS**:

* Tim Joseph Dumol (2009-09-29): Initial version.
* The Spyder Project Contributors: Several changes to make it work with Spyder.

Originally based on sagenb/misc/sphinxify.py from the
`Sage Notebook project <https://github.com/sagemath/sagenb>`_,
part of the `SageMath <https://www.sagemath.org/>`_ system.
    N)mkdtemp)escape)SystemMessage)EnvironmentFileSystemLoader)Sphinx)_get_module_data_pathget_module_source_pathencodingspyder.plugins.help.utilsstaticcssdark_cssbase_cssjsspyderutilshelpmathjaxMATHJAXPATH)relpath	attr_name
JQUERYPATHc                     d| v pd| v S )z;Returns whether a string contains Sphinx-style ReST markup.`z:: )	docstrings    Clib/python3.11/site-packages/spyder/plugins/help/utils/sphinxify.pyis_sphinx_markupr!   I   s     91	 12    c                     t                      }t          t          j        t          d                    |_        |                    d          }|                    ||           S )z-Print a warning message on the rich text view	templateszwarning.html)css_pathtextr   r   ospjoinCONFDIR_PATHloaderget_templaterender)messager%   envwarnings       r    r0   r0   O   sO    
--C!#(<"E"EFFCJ~..G>>8'>:::r"   c                     t                      }t          t          j        t          d                    |_        |                    d          }|                    || |||          S )z+Print a usage message on the rich text viewr$   z
usage.html)r%   titleintro_messagetutorial_messagetutorialr'   )r2   r.   r4   r5   r%   r/   usages          r    r6   r6   W   sb    
--C!#(<"E"EFFCJ\**E<<g)9H  N N Nr"   c                     t                      }t          t          j        t          d                    |_        |                    d          }|                    |||           S )z,Print loading message on the rich text view.r$   zloading.html)r%   loading_imgr.   r'   )r.   r8   r%   r/   loadings        r    r9   r9   `   s^    
--C!#(<"E"EFFCJ~..G>>{G  E E Er"    Fc                    |r&t           j        dk    r|                    dd          }|rdnd| ||||t          |t          t
          t          t          j        dk     rdndt          j        dk     rdndt          j
        d}|S )	aD  
    Generate the html_context dictionary for our Sphinx conf file.

    This is a set of variables to be passed to the Jinja template engine and
    that are used to control how the webpage is rendered in connection with
    Sphinx

    Parameters
    ----------
    name : str
        Object's name.
    note : str
        A note describing what type has the function or method being
        introspected
    argspec : str
        Argspec of the the function or method being introspected
    math : bool
        Turn on/off Latex rendering on the OI. If False, Latex will be shown in
        plain text.
    collapse : bool
        Collapse sections
    img_path : str
        Path for images relative to the file containing the docstring

    Returns
    -------
    A dict of strings to be used by Jinja to generate the webpage
    nt\/truer:   z1.1z2.0)math_onnameargspecnotecollapseimg_pathbase_css_pathr%   js_pathjquery_pathmathjax_pathright_sphinx_versionsphinx_version_2platform)osrA   replaceBASE_CSS_PATHJS_PATHJQUERY_PATHMATHJAX_PATHsphinx__version__sysrL   )rA   rB   rC   mathrD   rE   r%   contexts           r    generate_contextrX   i   s    >  /BGtOO##D#..
  'R$ "$*$6$>$>bbF & 2U : :"",!  ( Nr"   htmlc                    t          j        t          d                    }t                      }t	          j        |          }t          j        |d          }d}t          j        dk    rwt          j	        |          j
        d         }t          j	        |          j
        d         }||k    }|r1t                      }t	          j        |          }t          |           t          j        |d          }	|dk    rd}
nd	}
t          j        |d
|
z             }|d         r4|d         r,|                     dd          } |                     dd          } t          |d                   }dD ]}|                    |d|z   dz             }||d<   t          j        |	dd          }|                    |            |                                 d|i}t          j        |d          }t%          ||||||ddddd          }	 |                    d|	g           n.# t(          $ r! t+          d          }t-          |          cY S w xY wt          j        |          r@t          j        |dd                                          }|                    dd           }nt+          d          }t-          |          S |rt3          j        |d!           t3          j        |d!           |S )"a  
    Runs Sphinx on a docstring and outputs the processed documentation.

    Parameters
    ----------
    docstring : str
        a ReST-formatted docstring

    context : dict
        Variables to be passed to the layout template to control how its
        rendered (through the Sphinx variable *html_context*).

    buildername:  str
        It can be either `html` or `text`.

    Returns
    -------
    An Sphinx-processed string, in either HTML or plain text format, depending
    on the value of `buildername`
    r   _buildFr<   r   zdocstring.rstrY   z.htmlz.txtr   rJ   r@   z\\z\\\\z\**rB   )=,()r\   z**z <span class="argspec-highlight">z</span>wzutf-8r   html_contextdoctreesNT)statusr0   freshenvwarningiserrortagsz`It was not possible to generate rich text help for this object.</br>Please see it in plain text.rz<pre>z<pre class="literal-block">)ignore_errors)r(   r)   r   r   r   to_unicode_from_fsrM   rA   pathlibPathpartsgenerate_configurationrN   r   codecsopenwritecloser   buildr   r	   r0   existsreadshutilrmtree)r   rW   buildernameconfdirsrcdirdestdirtemp_confdir_neededdrive_confdirdrive_srcdirrst_namesuffixoutput_namerB   chardoc_fileconfoverrides
doctreedir
sphinx_appoutputs                      r    	sphinxifyr      s'   , h-.IJJKKGYYF(00Fhvx((G	w$  W--3A6|F++1!4+|; 	,iiG1'::G"7+++x00Hf(7K&$899K %& 279+= 2%%fj99	 %%eS11	 WY'((G/ P P//$;dBYNP P GI{8S7;;;HNN9NN#W-M&*--J*k%dD!%e$H H HJz****    3 4 4 v	 z+ [#@@@EEGG)FGG 3 4 4 v 3gT2222
M&----Ms   H (IIc                    t          j        t          d          d          }t          j        t          j        t          d          d          }t	          j        t          j        | d                     t	          j        t          j        | d                     t          j        ||            t          j        |t          j        | d                     t          t          j        | d          d          	                    d           t          t          j        | dd	          d          	                    d           d
S )z
    Generates a Sphinx configuration in `directory`.

    Parameters
    ----------
    directory : str
        Base directory to use
    r   zconf.pyr$   zlayout.htmlr   z__init__.pyra   r:   emptyN)
r(   r)   r   r*   rM   makedirsrv   copyrp   rq   )	directoryconflayouts      r    rn   rn   	  s    8*+FGG D Xch|[99=IIFKK00111KH--...
Ki   
KK88999)]	+	+S1177;;;)Xw	/	/55;;B?????r"   )rY   )*__doc__ro   rM   os.pathpathr(   rk   rv   rU   tempfiler   xml.sax.saxutilsr   docutils.utilsr   jinja2r   r   rS   sphinx.applicationr   spyder.config.baser	   r
   r   spyder.utilsr   r*   r)   CSS_PATHDARK_CSS_PATHrO   rP   rR   rQ   r!   r0   r6   r9   rX   r   rn   r   r"   r    <module>r      s     				         



       # # # # # # : 9 9 9 9 9 0 0 0 0 0 0 0 0  % % % % % %8 8 8 8 8 8 8 8 8 8 ! ! ! ! ! ! &%&ABB38L(E22x<<x<<
#(<
&
& $#H,4CHWf5<i-I -I.;= = =
 #"8+338GV4;,= ,=-9; ; ;3 3 3 ' ; ; ; ; @H N N N N ,4 E E E E br 86 6 6 6rd d d dN@ @ @ @ @r"   