
    -Ph                          d Z dZddlZddlmZ ddl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)	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    Y/var/www/html/test/jupyter/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titler.   s	            r"   r   zSectNum.update_section_numbers/   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_idr@   toc_backlinks
attributesupdater   build_contentslenreplace_self)r!   toc_by_writerr   r   contentss        r"   r#   zContents.applyW   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                 2   |dz  }d |D             }g }| 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>u   s)    MMMTZem-L-LMDMMMr$   r	   r   r*   r   refidr?   z	toc-entry)suggested_prefix)entrytoprR   rS   r)   zauto-toc)r   r   r   r   r   copy_and_filterr   	referencer   set_id	paragraph	list_itemr@   	next_noderB   rF   appendbullet_list)r!   r1   levelsectionsentriesr	   r,   r4   r*   	entrytextrU   ref_idrR   itemsubsectsrJ   s                   r"   rF   zContents.build_contentss   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"222OOEO44<>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!   r1   visitors      r"   rT   zContents.copy_and_filter   s5     //w%%'''r$   N)r   )r5   r6   r7   r8   r9   r#   rF   rT   r%   r$   r"   r;   r;   E   s\          K K K8   B( ( ( ( (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 )rd   c                 4    |                                  j        S N)get_tree_copychildrenr    s    r"   rf   zContentsFilter.get_entry_text   s    !!##,,r$   c                     t           j        rj   r   SkipNoder!   r1   s     r"   visit_citation_referencez'ContentsFilter.visit_citation_reference   
    nr$   c                     t           j        rj   rn   rp   s     r"   visit_footnote_referencez'ContentsFilter.visit_footnote_reference   rr   r$   c                     |                     d          r2| j                            t          j        |d                              t          j        )Nalt)hasattrr   rZ   r   Textro   rp   s     r"   visit_imagezContentsFilter.visit_image   sB    << 	8Kuz$u+66777nr$   c                     t           j        rj   )r   SkipDeparturerp   s     r"    ignore_node_but_process_childrenz/ContentsFilter.ignore_node_but_process_children   s    !!r$   N)r5   r6   r7   rf   rq   rt   ry   r|   visit_problematicvisit_referencevisit_targetr%   r$   r"   rd   rd      sk        - - -      
" " " 96O3LLLr$   rd   )r8   __docformat__r   docutilsr   docutils.transformsr   r   r;   TreeCopyVisitorrd   r%   r$   r"   <module>r      s   
  # 


       ) ) ) ) ) )1 1 1 1 1i 1 1 1hS( S( S( S( S(y S( S( S(l4 4 4 4 4U* 4 4 4 4 4r$   