U
    ZSh                     @   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.
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 d S )Nr   )r   choicer   backlinks_values)argvalue r   X/root/rtd-docs/venv/lib/python3.8/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rz| jd }| j|| j\}}tj|df| }n&g }d| jkrd }ntd|jd }tjdgd}|d  | jdg 7  < | j  \|_|_| jd	8  _d| jkr|d d |r| }||7 }n
|jd }t|}||sH|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_code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    language
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_specr6   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/   r0   r'   r   r    r1   )r2   r.   r   r   r   r6   `   s    zSectnum.runN)	r7   r8   r9   r:   intr   Zunchanged_requiredr<   r6   r   r   r   r   r=   W   s   r=   c                   @   s   e Zd ZdZdZdd ZdS )HeaderzContents of document header.Tc                 C   s0   |    | jj  }| j| j| j| g S rA   )	assert_has_contentr   r    get_decoration
get_headerr$   nested_parsecontentcontent_offset)r2   headerr   r   r   r6   m   s    z
Header.runNr7   r8   r9   r:   Zhas_contentr6   r   r   r   r   rC   g   s   rC   c                   @   s   e Zd ZdZdZdd ZdS )FooterzContents of document footer.Tc                 C   s0   |    | jj  }| j| j| j| g S rA   )	rD   r   r    rE   Z
get_footerr$   rG   rH   rI   )r2   footerr   r   r   r6   z   s    z
Footer.runNrK   r   r   r   r   rL   t   s   rL   N)r:   __docformat__Zdocutilsr   r   Zdocutils.transformsr   Zdocutils.parsers.rstr   r   r   r=   rC   rL   r   r   r   r   <module>   s   F