
    dd                          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
y)z'
Transforms related to document parts.
reStructuredText    N)nodes)	Transformc                   $    e Zd ZdZdZ	 d ZddZy)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                  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    ;/usr/lib/python3/dist-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_numbers/   s    
GooG 	E%/ CL?2a!OOsxx'884;;F'(&K)	 Q	* !f4==(//wF1	r$   N) r   )__name__
__module____qualname____doc__default_priorityr#   r   r4   r$   r"   r   r      s     .@ r$   r   c                   (    e Zd ZdZdZ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                     t        | j                  j                  dd      }| 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                  | _
        |r_| j                  j
                  j                  j                  |       | j                  j
                  j                  | j                         y | 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_idr@   toc_backlinks
attributesupdater   build_contentslenreplace_self)r!   toc_by_writerr   r   contentss        r"   r#   zContents.applyW   sj    6 6O..((g--44I!)U]];$Y?%,,	 ")U]];$Y? Inn++E215'!$[1DN!]]33AADNNN!!,,33G<NN!!((8**95H8}++H5%%,,33DNN4I4IJr$   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   refidr?   z	toc-entry)suggested_prefix)entrytoprN   rO   r(   zauto-toc)r*   r   r+   r   r   r   r   r   copy_and_filter	referencer   set_id	paragraph	list_itemr@   	next_noderB   rF   appendbullet_list)r!   r0   levelsectsectionsentriesr	   r+   r3   r)   	entrytextrQ   ref_idrN   itemsubsectsrJ   s                    r"   rF   zContents.build_contentss   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!   r0   visitors      r"   rP   zContents.copy_and_filter   s+     /w%%''r$   N)r   )r5   r6   r7   r8   r9   r#   rF   rP   r4   r$   r"   r;   r;   E   s      K8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)ra   c                 6    | j                         j                  S N)get_tree_copychildrenr    s    r"   rc   zContentsFilter.get_entry_text   s    !!#,,,r$   c                 "    t         j                  rg   r   SkipNoder!   r0   s     r"   visit_citation_referencez'ContentsFilter.visit_citation_reference       nnr$   c                 "    t         j                  rg   rk   rm   s     r"   visit_footnote_referencez'ContentsFilter.visit_footnote_reference   ro   r$   c                     |j                  d      r1| j                  j                  t        j                  |d                t        j
                  )Nalt)hasattrr   rV   r   Textrl   rm   s     r"   visit_imagezContentsFilter.visit_image   s7    <<KKuzz$u+67nnr$   c                 "    t         j                  rg   )r   SkipDeparturerm   s     r"    ignore_node_but_process_childrenz/ContentsFilter.ignore_node_but_process_children   s    !!!r$   N)r5   r6   r7   rc   rn   rq   rv   ry   visit_problematicvisit_referencevisit_targetr4   r$   r"   ra   ra      s-    -
" 96O3Lr$   ra   )r8   __docformat__r   docutilsr   docutils.transformsr   r   r;   TreeCopyVisitorra   r4   r$   r"   <module>r      sJ   
 #   )1i 1hS(y S(l4U** 4r$   