
    N&iP                         d Z dZddlZddlZddlmZmZ ddlmZm	Z	  G d de	          Z
 G d d	e	          Z G d
 dej                  ZdS )z'
Transforms related to document parts.
reStructuredText    N)nodesutils)TransformError	Transformc                   &    e Zd ZdZdZ	 d ZddZdS )	SectNumaS  
    Automatically assigns numbers to the titles of document sections.

    It is possible to limit the maximum section level for which the numbers
    are added.  For those sections that are auto-numbered, the "autonum"
    attribute is set, informing the contents table generator that a different
    form of the TOC should be used.
    i  c                    | j         j                            dd           | _        | j         j                            dd          | _        | j         j                            dd          | _        | j         j                            dd          | _        | j         j                            | j                    | j	        j
        j        r4| j        t          j        | _        |                     | j	                   d S | j        | j	        j
        _        | j        | j	        j
        _        | j        | j	        j
        _        | j        | j	        j
        _        d S )Ndepthstart   prefix suffix)	startnodedetailsgetmaxdepth
startvaluer   r   parentremovedocumentsettingssectnum_xformsysmaxsizeupdate_section_numberssectnum_depthsectnum_startsectnum_prefixsectnum_suffixselfs    f/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/docutils/transforms/parts.pyapplyzSectNum.apply    s   .227DAA.044Wa@@n,002>>n,002>>$$T^444=!/ 	@}$ #''6666637=DM"037?DM"048KDM"148KDM"111     r   c                    |dz  }|rd}n| j         }|D ]}t          |t          j                  r|t	          |          fz   }|d         }t          j        d| j        d                    |          z   | j        z   dz   dg          }|	                    d|           d|d<   || j
        k     r|                     |||           |dz  }d S )	Nr   r   r   .u      sectnum)classesauto)r   
isinstancer   sectionstr	generatedr   joinr   insertr   r   )	r#   noder   r   r*   childnumberstitler0   s	            r$   r   zSectNum.update_section_numbers0   s    
 	&GGoG 	 	E%//  CLL?2a!Osxx'8'884;F)*&K) ) )	 Q	*** !f4=((//wFFF1	 	r&   N)r'   r   )__name__
__module____qualname____doc__default_priorityr%   r   r'   r&   r$   r	   r	      sO          .@ @ @      r&   r	   c                   *    e Zd ZdZdZd ZddZd ZdS )	Contentsa  
    This transform generates a table of contents from the entire document tree
    or from a single branch.  It locates "section" elements and builds them
    into a nested bullet list, which is placed within a "topic" created by the
    contents directive.  A title is either explicitly specified, taken from
    the appropriate language module, or omitted (local table of contents).
    The depth may be specified.  Two-way references between the table of
    contents and section titles are generated (requires Writer support).

    This transform requires a startnode, which contains generation
    options and provides the location for the generated table of contents (the
    startnode is replaced by the table of contents "topic").
    i  c                 j   t          | j        j        dd          }| j        j        }d|v r| j        j        j        }t          |t          j                  sUt          |t          j                  s;|j        }t          |t          j                  st          |t          j                  ;n| j        }| j        j        d         d         | _	        d|v r|d         | _
        n| j        j        j        | _
        |rJ| j        j        j                            |           | j        j                            | j                   d S |                     |          }t!          |          r| j                            |           d S | j        j        j                            | j        j                   d S )Nuse_latex_tocFlocalidsr   	backlinks)getattrr   r   r   r   r   r-   r   r.   toc_idrB   toc_backlinks
attributesupdater   build_contentslenreplace_self)r#   toc_by_writerr   r   contentss        r$   r%   zContents.applyX   s    6OO.(g-4I!)U];; -$Y??- &,	 ")U];; -$Y??-
 In+E215'!!$[1DNN!]3ADN 		KN!,33G<<<N!((88888**955H8}} K++H55555%,33DN4IJJJJJr&   r   c                 6   |dz  }d |D             }g }d}| j         j                            dt          j                  }|D ]"}|d         }|                    d          }	|                     |          }
t          j        ddg|
R d|d         d         i}| j        	                    |d	
          }t          j
        dd|          }t          j        d|          }| j        dv rE|                    t          j                  &| j        dk    r||d<   n| j        dk    r
| j        |d<   ||k     r|                     ||          }||z  }|                    |           $|r1t          j        dg|R  }|	r|d                             d           |S g S )Nr   c                 F    g | ]}t          |t          j                  |S r'   )r-   r   r.   ).0sects     r$   
<listcomp>z+Contents.build_contents.<locals>.<listcomp>v   s)    MMMTZem-L-LMDMMMr&   r   r   r,   r   refidrA   z	toc-entry)suggested_prefix)entrytoprT   rU   r+   zauto-toc)r   r   r   r   r   copy_and_filterr   	referencer   set_id	paragraph	list_itemrB   	next_noderD   rH   appendbullet_list)r#   r3   levelsectionsentriesautonumr   r.   r6   r,   	entrytextrW   ref_idrT   itemsubsectsrL   s                    r$   rH   zContents.build_contentst   s   
MMTMMM&**7CK@@ 	! 	!GAJE99V$$D,,U33IB 4)24 4 4genQ6G 4 4I])));F * H HFOBI66E?2u--D#333__U_55=>W,,%+E'NN^u,,%)[E'Nu}}..w>> NN4     	(6g666H 7#**:666OIr&   c                 |    t          | j                  }|                    |           |                                S )z@Return a copy of a title, with references, images, etc. removed.)ContentsFilterr   	walkaboutget_entry_text)r#   r3   visitors      r$   rV   zContents.copy_and_filter   s5     //w%%'''r&   N)r   )r7   r8   r9   r:   r;   r%   rH   rV   r'   r&   r$   r=   r=   F   s\          K K K8       D( ( ( ( (r&   r=   c                   8    e Zd Zd Zd Zd Zd Zd ZeZeZ	eZ
dS )rg   c                 4    |                                  j        S N)get_tree_copychildrenr"   s    r$   ri   zContentsFilter.get_entry_text   s    !!##,,r&   c                     t           j        rm   r   SkipNoder#   r3   s     r$   visit_citation_referencez'ContentsFilter.visit_citation_reference   
    nr&   c                     t           j        rm   rq   rs   s     r$   visit_footnote_referencez'ContentsFilter.visit_footnote_reference   ru   r&   c                     |                     d          r2| j                            t          j        |d                              t          j        )Nalt)hasattrr   r\   r   Textrr   rs   s     r$   visit_imagezContentsFilter.visit_image   sB    << 	8Kuz$u+66777nr&   c                     t           j        rm   )r   SkipDeparturers   s     r$    ignore_node_but_process_childrenz/ContentsFilter.ignore_node_but_process_children   s    !!r&   N)r7   r8   r9   ri   rt   rw   r|   r   visit_problematicvisit_referencevisit_targetr'   r&   r$   rg   rg      sk        - - -      
" " " 96O3LLLr&   rg   )r:   __docformat__rer   docutilsr   r   docutils.transformsr   r   r	   r=   TreeCopyVisitorrg   r'   r&   r$   <module>r      s   
  # 
			 



 ! ! ! ! ! ! ! ! 9 9 9 9 9 9 9 91 1 1 1 1i 1 1 1hT( T( T( T( T(y T( T( T(n4 4 4 4 4U* 4 4 4 4 4r&   