
    <i                        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dS )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d	S )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  returnNonec                   | 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    /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.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titler1   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
   )r(   r   )__name__
__module____qualname____doc__default_priorityr&   r   r(   r'   r%   r   r      sZ          .@ @ @ @       r'   r   c                  ,    e Zd ZdZdZd
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  r	   r
   c                   t          | j        j        dd          }|rd S | 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        | _
        |                     |          }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_idrD   toc_backlinksbuild_contentslenreplace_selfr   )r$   toc_by_writerr   r   contentss        r%   r&   zContents.applyX   sP    6OO 	F.(g-4I!)U];; -$Y??- &,	 ")U];; -$Y??-
 In+E215'!!$[1DNN!]3ADN&&y11x== 	GN''11111N!(//0EFFFFFr'   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>t   s)    MMMTZem-L-LMDMMMr'   r   r   r-   r   refidrC   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_itemrD   	next_noderF   rH   appendbullet_list)r$   r4   levelsectionsentriesr   r/   r7   r-   	entrytextrW   ref_idrT   itemsubsectsrL   s                   r%   rH   zContents.build_contentsr   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$   r4   visitors      r%   rV   zContents.copy_and_filter   s5     //w%%'''r'   Nr8   )r   )r9   r:   r;   r<   r=   r&   rH   rV   r(   r'   r%   r?   r?   F   sb          G G G G4   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 )rf   c                4    |                                  j        S N)get_tree_copychildrenr#   s    r%   rh   zContentsFilter.get_entry_text   s    !!##,,r'   c                    t           j        rl   r   SkipNoder$   r4   s     r%   visit_citation_referencez'ContentsFilter.visit_citation_reference   
    nr'   c                    t           j        rl   rp   rr   s     r%   visit_footnote_referencez'ContentsFilter.visit_footnote_reference   rt   r'   c                    |                     d          r2| j                            t          j        |d                              t          j        )Nalt)hasattrr   r\   r   Textrq   rr   s     r%   visit_imagezContentsFilter.visit_image   sB    << 	8Kuz$u+66777nr'   c                    t           j        rl   )r   SkipDeparturerr   s     r%    ignore_node_but_process_childrenz/ContentsFilter.ignore_node_but_process_children   s    !!r'   N)r9   r:   r;   rh   rs   rv   r{   r~   visit_problematicvisit_referencevisit_targetr(   r'   r%   rf   rf      sk        - - -      
" " " 96O3LLLr'   rf   )r<   
__future__r   __docformat__r   docutilsr   docutils.transformsr   r   r?   TreeCopyVisitorrf   r(   r'   r%   <module>r      s   
  # " " " " "" 



       ) ) ) ) ) )1 1 1 1 1i 1 1 1hQ( Q( Q( Q( Q(y Q( Q( Q(h4 4 4 4 4U* 4 4 4 4 4r'   