
    -Ph                     |    d Z ddlZddlmZ ddlmZ ddlmZ  ej        e	          Z
 G d d          Zdefd	ZdS )
z5A custom Sphinx HTML Translator for Bootstrap layout.    N)Sphinx)autosummary_table)loggingc                   <     e Zd ZdZ fdZ fdZd Z fdZ xZS )BootstrapHTML5TranslatorMixinzMixin HTML Translator for a Bootstrap-ified Sphinx layout.

    Only a couple of functions have been overridden to produce valid HTML to be
    directly styled with Bootstrap, and fulfill acessibility best practices.
    c                 R     t                      j        |i | d| j        _        d S )Ntable)super__init__settingstable_style)selfargskwds	__class__s      ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/pydata_sphinx_theme/translator.pyr   z&BootstrapHTML5TranslatorMixin.__init__   s/    $'$'''$+!!!    c                 z    |                     d          dk    r	d|vrd|d<    t                      j        |i |S )zoPerform small modifications to tags.

        - ensure aria-level is set for any tag with heading role
        ROLEheadingz
ARIA-LEVEL2)getr
   starttag)r   r   kwargsr   s      r   r   z&BootstrapHTML5TranslatorMixin.starttag   sL    
 ::f**|6/I/I#&F< uww0000r   c                    i }| j                             d           d | j        j                            d          D             }t          |j        t                    r|dgz  }d|v rd|d          |d<   d|v r|                    d	|d                     | j                            d
            | j	        |dfdd
                    |          i|}| j                            |           dS )z
        Custom visit table method.

        Copy of sphinx source to *not* add 'docutils' and 'align-default' classes but
        add 'table' class.
        r   c                 8    g | ]}|                     d           S )z 	
)strip).0clss     r   
<listcomp>z=BootstrapHTML5TranslatorMixin.visit_table.<locals>.<listcomp>/   s$    VVV#399W%%VVVr   ,autosummarywidthzwidth: stylealignztable-z,<div class="pst-scrollable-table-container">r	   CLASS N)_table_row_indicesappendr   r   split
isinstanceparentr   bodyr   join)r   nodeattsclassestags        r   visit_tablez)BootstrapHTML5TranslatorMixin.visit_table"   s    &&q))) WV1J1P1PQT1U1UVVV dk#455 	'&G d??5d7m55DM d??NN3DM33444 		GHHHdmD'KK'1B1BKdKK	r   c                 ~    t                                          |           | j                            d           dS )zg
        Custom depart_table method to close the scrollable div we add in
        visit_table.
        z</div>
N)r
   depart_tabler-   r)   )r   r/   r   s     r   r5   z*BootstrapHTML5TranslatorMixin.depart_tableC   s9    
 	T"""	$$$$$r   )	__name__
__module____qualname____doc__r   r   r3   r5   __classcell__)r   s   @r   r   r      s         , , , , ,1 1 1 1 1  B% % % % % % % % %r   r   appc                    | j         j                                        s`	 | j        j        }n# t
          $ r Y dS w xY wt          j        dt          |fi           }| 	                    | j        j
        |d           dS | j         j                                        D ]K\  }}| j        j        dk    rt          j        dt          |fi           }| 	                    ||d           LdS )a  
    Add bootstrap HTML functionality if we are using an HTML translator.

    This re-uses the pre-existing Sphinx translator and adds extra functionality
    defined in ``BootstrapHTML5TranslatorMixin``.
    This way we can retain the original translator's
    behavior and configuration, and _only_ add the extra bootstrap rules.
    If we don't detect an HTML-based translator, then we do nothing.
    NBootstrapHTML5TranslatorT)overridehtml)registrytranslatorsitemsbuilderdefault_translator_classAttributeErrortypes	new_classr   set_translatornameformat)r;   rD   
translatorrI   klasss        r   setup_translatorsrM   L   s*    <#))++ @	'*{'K$$ 	 	 	FF	 _&-( 
 

 	3;+Z$GGGGG<399;; 	@ 	@KD%{!V++*1  J tZ$????	@ 	@s   - 
;;)r9   rF   sphinx.applicationr   sphinx.ext.autosummaryr   sphinx.utilr   	getLoggerr6   loggerr   rM    r   r   <module>rT      s    ; ;  % % % % % % 4 4 4 4 4 4       
	8	$	$<% <% <% <% <% <% <% <%~(@6 (@ (@ (@ (@ (@ (@r   