
    Ki                        d Z ddlm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y)z'
Transforms related to document parts.
    )annotationsreStructuredTextN)nodes)	Transformc                  (    e Zd ZdZdZ	 ddZdddZy)SectNumaP  
    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 "auto"
    attribute is set, informing the contents table generator that a different
    form of the TOC should be used.
    i  c                   | j                   j                  j                  dd       | _        | j                   j                  j                  dd      | _        | j                   j                  j                  dd      | _        | j                   j                  j                  dd      | _        | j                   j                  j                  | j                          | j                  j                  j                  r=| j                  t        j                  | _        | j                  | j                         y | j                  | j                  j                  _        | j                  | j                  j                  _        | j
                  | j                  j                  _        | j                  | j                  j                  _        y )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    e/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docutils/transforms/parts.pyapplyzSectNum.apply    s(   ..227DA..0044Wa@nn,,002>nn,,002>$$T^^4==!!//}}$ #''637==DMM""037??DMM""048KKDMM""148KKDMM""1    c                   |dz  }|rd}n| j                   }|D ]  }t        |t        j                        s|t	        |      fz   }|d   }t        j
                  d| j                  dj                  |      z   | j                  z   dz   dg      }|j                  d|       d|d<   || j                  k  r| j                  |||       |dz  } y )	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_numbers0   s    
GooG 	E%/ CL?2a!OOsxx'884;;F'(&K)	 Q	* !f4==(//wF1	r%   NreturnNone) r   )__name__
__module____qualname____doc__default_priorityr$   r   r8   r%   r#   r   r      s     .@ r%   r   c                  *    e Zd ZdZdZddZddZd Zy)	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                d   t        | j                  j                  dd      }|ry | j                  j                  }d|v r| j                  j
                  j
                  }t        |t        j                        sht        |t        j                        sN|j
                  }t        |t        j                        s(t        |t        j                        sAn| j                  }| j                  j
                  d   d   | _	        d|v r|d   | _
        n%| j                  j                  j                  | _
        | j                  |      }t        |      r| j                  j                  |       y | j                  j
                  j
                  j                  | j                  j
                         y )Nuse_latex_tocFlocalidsr   	backlinks)getattrr   r   r   r   r   r+   r   r,   toc_idrD   toc_backlinksbuild_contentslenreplace_selfr   )r"   toc_by_writerr   r   contentss        r#   r$   zContents.applyX   s3    6 6O..((g--44I!)U]];$Y?%,,	 ")U]];$Y? Inn++E215'!$[1DN!]]33AADN&&y1x=NN''1NN!!((//0E0EFr%   c                   |dz  }|D cg c]  }t        |t        j                        s|! }}g }| j                  j                  j                  dt        j                        }|D ]!  }|d   }|j                  d      }	| j                  |      }
t        j                  ddg|
d|d   d   i}| j                  j                  |d	      }t        j                  dd|      }t        j                  d|      }| j                  d
v rR|j                  t        j                        3| j                  dk(  r||d<   n| j                  dk(  r| j                   |d<   ||k  r| j#                  ||      }||z  }|j%                  |       $ |r.t        j&                  dg| }	r|d   j%                  d       |S g S c c}w )Nr   r
   r   r*   r   refidrC   z	toc-entry)suggested_prefix)entrytoprP   rQ   r)   zauto-toc)r+   r   r,   r   r   r   r   r   copy_and_filter	referencer   set_id	paragraph	list_itemrD   	next_noderF   rH   appendbullet_list)r"   r1   levelsectsectionsentriesr
   r,   r4   r*   	entrytextrS   ref_idrP   itemsubsectsrL   s                    r#   rH   zContents.build_contentsr   s   
%)MTZemm-LDMM&&**7CKK@ 	!GAJE99V$D,,U3IB 4)24genQ6G 4I]])));F * HFOOBI6E??2u-D"22OOEOO4<>>W,%+E'N^^u,%)[[E'Nu}..w> NN4 '	!( ((6g6H#**:6OI; Ns
   F?F?c                n    t        | j                        }|j                  |       |j                         S )z@Return a copy of a title, with references, images, etc. removed.)ContentsFilterr   	walkaboutget_entry_text)r"   r1   visitors      r#   rR   zContents.copy_and_filter   s+     /w%%''r%   Nr5   )r   )r9   r:   r;   r<   r=   r$   rH   rR   r8   r%   r#   r?   r?   F   s      G4B(r%   r?   c                  6    e Zd Zd Zd Zd Zd Zd ZeZeZ	eZ
y)rc   c                6    | j                         j                  S N)get_tree_copychildrenr!   s    r#   re   zContentsFilter.get_entry_text   s    !!#,,,r%   c                "    t         j                  ri   r   SkipNoder"   r1   s     r#   visit_citation_referencez'ContentsFilter.visit_citation_reference       nnr%   c                "    t         j                  ri   rm   ro   s     r#   visit_footnote_referencez'ContentsFilter.visit_footnote_reference   rq   r%   c                    |j                  d      r1| j                  j                  t        j                  |d                t        j
                  )Nalt)hasattrr   rX   r   Textrn   ro   s     r#   visit_imagezContentsFilter.visit_image   s7    <<KKuzz$u+67nnr%   c                "    t         j                  ri   )r   SkipDeparturero   s     r#    ignore_node_but_process_childrenz/ContentsFilter.ignore_node_but_process_children   s    !!!r%   N)r9   r:   r;   re   rp   rs   rx   r{   visit_problematicvisit_referencevisit_targetr8   r%   r#   rc   rc      s-    -
" 96O3Lr%   rc   )r<   
__future__r   __docformat__r   docutilsr   docutils.transformsr   r   r?   TreeCopyVisitorrc   r8   r%   r#   <module>r      sK   
 #" 
  )1i 1hQ(y Q(h4U** 4r%   