
    k7i                        S r SSKJr  SrSSKrSSKJr  SSKJr   " S S\5      r	 " S	 S
\5      r
 " S S\R                  5      rg)z'
Transforms related to document parts.
    )annotationsreStructuredTextN)nodes)	Transformc                  6    \ rS rSrSrSr SS jrS	SS jjrSrg)
SectNum   a8  
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                   U R                   R                  R                  SS 5      U l        U R                   R                  R                  SS5      U l        U R                   R                  R                  SS5      U l        U R                   R                  R                  SS5      U l        U R                   R                  R                  U R                   5        U R                  R                  R                  (       a>  U R                  c  [        R                  U l        U R                  U R                  5        g U R                  U R                  R                  l        U R                  U R                  R                  l        U R
                  U R                  R                  l        U R                  U R                  R                  l        g )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    S/home/james-whalen/.local/lib/python3.13/site-packages/docutils/transforms/parts.pyapply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                   US-  nU(       a  SnOU R                   nU H  n[        U[        R                  5      (       d  M$  U[	        U5      4-   nUS   n[        R
                  " SU R                  SR                  U5      -   U R                  -   S-   S/S9nUR                  SU5        SUS'   X0R                  :  a  U R                  XVU5        US-  nM     g )	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   SectNum.update_section_numbers0   s    
GooGE%// CL?2a!OOsxx'884;;F'(&K)	 Q	* !f==(//F1 r'   )r   r   r   r   NreturnNone) r   )	__name__
__module____qualname____firstlineno____doc__default_priorityr%   r   __static_attributes__r;   r'   r$   r   r      s"     .@  r'   r   c                  6    \ rS rSrSrSrS	S jrS
S jrS rSr	g)ContentsF   a  
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                   [        U R                  R                  SS5      nU(       a  g U R                  R                  nSU;   a  U R                  R
                  R
                  n[        U[        R                  5      (       dk  [        U[        R                  5      (       dL  UR
                  n[        U[        R                  5      (       d!  [        U[        R                  5      (       d  ML  OU R                  nU R                  R
                  S   S   U l	        SU;   a  US   U l
        O%U R                  R                  R                  U l
        U R                  U5      n[        U5      (       a  U R                  R                  U5        g U R                  R
                  R
                  R                  U R                  R
                  5        g )Nuse_latex_tocFlocalidsr   	backlinks)getattrr   r   r   r   r   r-   r   r.   toc_idrJ   toc_backlinksbuild_contentslenreplace_selfr   )r#   toc_by_writerr   r   contentss        r$   r%   Contents.applyX   sB    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                   US-  nU Vs/ s H&  n[        U[        R                  5      (       d  M$  UPM(     nn/ nU R                  R                  R                  S[        R                  5      nU GH$  nUS   nUR                  S5      n	U R                  U5      n
[        R                  " SS/U
Q7SUS   S   06nU R                  R                  USS	9n[        R                  " SSU5      n[        R                  " SU5      nU R                  S
;   aT  UR                  [        R                  5      c4  U R                  S:X  a  XS'   OU R                  S:X  a  U R                   US'   X&:  a  U R#                  Xr5      nX-  nUR%                  U5        GM'     U(       a4  [        R&                  " S/UQ76 nW	(       a  US   R%                  S5        U$ / $ s  snf )Nr   r   r   r,   r   refidrI   z	toc-entry)suggested_prefix)entrytoprW   rX   r+   zauto-toc)r-   r   r.   r   r   r   r   r   copy_and_filter	referencer   set_id	paragraph	list_itemrJ   	next_noderL   rN   appendbullet_list)r#   r3   levelsectsectionsentriesr   r.   r6   r,   	entrytextrZ   ref_idrW   itemsubsectsrR   s                    r$   rN   Contents.build_contentsr   s   
%)MTTZemm-LDT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,%+'N^^u,%)[[E'N}..w> NN4 '  ( ((6g6H#**:6OI; Ns
   #GGc                n    [        U R                  5      nUR                  U5        UR                  5       $ )z@Return a copy of a title, with references, images, etc. removed.)ContentsFilterr   	walkaboutget_entry_text)r#   r3   visitors      r$   rY   Contents.copy_and_filter   s+     /w%%''r'   )rJ   rL   Nr8   )r   )
r<   r=   r>   r?   r@   rA   r%   rN   rY   rB   r;   r'   r$   rD   rD   F   s      G4B(r'   rD   c                  >    \ rS rSrS rS rS rS rS r\r	\r
\rSrg)	rk      c                6    U R                  5       R                  $ N)get_tree_copychildrenr"   s    r$   rm   ContentsFilter.get_entry_text   s    !!#,,,r'   c                "    [         R                  ers   r   SkipNoder#   r3   s     r$   visit_citation_reference'ContentsFilter.visit_citation_reference       nnr'   c                "    [         R                  ers   rx   rz   s     r$   visit_footnote_reference'ContentsFilter.visit_footnote_reference   r}   r'   c                    UR                  S5      (       a2  U R                  R                  [        R                  " US   5      5        [        R
                  e)Nalt)hasattrr   r_   r   Textry   rz   s     r$   visit_imageContentsFilter.visit_image   s:    <<KKuzz$u+67nnr'   c                "    [         R                  ers   )r   SkipDeparturerz   s     r$    ignore_node_but_process_children/ContentsFilter.ignore_node_but_process_children   s    !!!r'   r;   N)r<   r=   r>   r?   rm   r{   r   r   r   visit_problematicvisit_referencevisit_targetrB   r;   r'   r$   rk   rk      s-    -
" 96O3Lr'   rk   )r@   
__future__r   __docformat__r   docutilsr   docutils.transformsr   r   rD   TreeCopyVisitorrk   r;   r'   r$   <module>r      sK   
 #" 
  )1i 1hQ(y Q(h4U** 4r'   