o
    2\a                     @   s   d Z dZddlmZmZ ddlmZ ddlmZ ddlm	Z	 G dd deZ
G d	d
 d
eZG dd deZG dd deZdS )z 
Directives for document parts.
ZreStructuredText    )nodes	languages)parts)	Directive)
directivesc                   @   s@   e Zd ZdZdZdd ZdZdZej	ej
eejdZdd	 Zd
S )Contentsa  
    Table of contents.

    The table of contents is generated in two passes: initial parse and
    transform.  During the initial parse, a 'pending' element is generated
    which acts as a placeholder, storing the TOC title and any options
    internally.  At a later stage in the processing, the 'pending' element is
    replaced by a 'topic' element, a title and the table of contents proper.
    )topentrynonec                 C   s   t | tj}|dkrd S |S )Nr
   )r   choicer   backlinks_values)argvalue r   Iusr/lib/python3.10/site-packages/docutils/parsers/rst/directives/parts.py	backlinks   s   zContents.backlinks   T)depthlocalr   classc           
      C   s  | j jst| j jtjs| d| j | j j}t	
|jj|j}| jr>| jd }| j|| j\}}tj|dg|R  }ng }d| jv rHd }n	td|jd }tjdgd}|d  | jdg 7  < | j  \|_|_| jd	8  _d| jv r|d d |r| }||7 }n|jd }t|}||s|d
 | || tjt j!| j"d}	|	j#$| j |%|	 ||	7 }|g| S )NzBThe "%s" directive may not be used within topics or body elements.r    r   contents)classesr   r   r   names)Z	rawsource)&state_machineZmatch_titles
isinstancenoder   Zsidebarerrornamedocumentr   Zget_languagesettingsZlanguage_codeZreporter	argumentsstateZinline_textlinenotitleoptionslabelstopicgetZget_source_and_linesourcelineappendZastextZfully_normalize_nameZhas_nameZnote_implicit_targetpendingr   r   Z
block_textdetailsupdatenote_pending)
selfr   languageZ
title_textZ
text_nodesmessagesr$   r'   r   r,   r   r   r   run-   sN   










zContents.runN)__name__
__module____qualname____doc__r   r   Zoptional_argumentsZfinal_argument_whitespacer   Znonnegative_intflagZclass_optionoption_specr3   r   r   r   r   r      s    
r   c                   @   s*   e Zd ZdZeeejejdZdd ZdS )SectnumzAutomatic section numbering.)r   startprefixsuffixc                 C   s.   t tj}|j| j | jj	| |gS N)
r   r,   r   ZSectNumr-   r.   r%   r   r   r/   )r0   r,   r   r   r   r3   `   s   zSectnum.runN)	r4   r5   r6   r7   intr   Zunchanged_requiredr9   r3   r   r   r   r   r:   W   s    r:   c                   @      e Zd ZdZdZdd ZdS )HeaderzContents of document header.Tc                 C   0   |    | jj  }| j| j| j| g S r>   )	assert_has_contentr   r   get_decorationZ
get_headerr"   nested_parsecontentcontent_offset)r0   headerr   r   r   r3   m      z
Header.runNr4   r5   r6   r7   Zhas_contentr3   r   r   r   r   rA   g       rA   c                   @   r@   )FooterzContents of document footer.Tc                 C   rB   r>   )	rC   r   r   rD   Z
get_footerr"   rE   rF   rG   )r0   Zfooterr   r   r   r3   z   rI   z
Footer.runNrJ   r   r   r   r   rL   t   rK   rL   N)r7   Z__docformat__docutilsr   r   Zdocutils.transformsr   Zdocutils.parsers.rstr   r   r   r:   rA   rL   r   r   r   r   <module>   s   F