B “äî\Eã@sndZdZddlZddlZddlmZmZddlmZm Z Gdd„de ƒZ Gdd „d e ƒZ Gd d „d ej ƒZ dS) z' Transforms related to document parts. ZreStructuredTextéN)ÚnodesÚutils)ÚTransformErrorÚ Transformc@s&eZdZdZdZdd„Zd dd„Zd 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ÆcCs¶|jj dd¡|_|jj dd¡|_|jj dd¡|_|jj dd¡|_|jj |j¡|j j j r‚|jdkrtt j |_| |j ¡n0|j|j j _|j|j j _|j|j j _|j|j j _dS)NÚdepthÚstartéÚprefixÚÚsuffix)Ú startnodeÚdetailsÚgetÚmaxdepthÚ startvaluer r ÚparentÚremoveÚdocumentÚsettingsZ sectnum_xformÚsysÚmaxsizeÚupdate_section_numbersZ sectnum_depthZ sectnum_startZsectnum_prefixZsectnum_suffix)Úself©rú=/tmp/pip-build-uw_ogi45/docutils/docutils/transforms/parts.pyÚapply s     z SectNum.applyrrc Cs¨|d7}|rd}n|j}xŠ|D]‚}t|tjƒr|t|ƒf}|d}tjd|jd |¡|jddgd}|  d|¡d|d<||j kr˜|  |||¡|d7}qWdS) Nr rr Ú.u   Úsectnum)ÚclassesÚauto) rÚ isinstancerÚsectionÚstrÚ generatedr Újoinr Úinsertrr) rÚnoder rrÚchildZnumbersÚtitler$rrrr0s"     zSectNum.update_section_numbersN)rr)Ú__name__Ú __module__Ú __qualname__Ú__doc__Údefault_priorityrrrrrrrs rc@s.eZdZdZdZdd„Zd dd„Zdd „Zd 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ÐcCsþy|jjj}Wntk r&d}YnX|jj}d|krh|jjj}x*t|tj ƒsdt|tjƒsd|j}qDWn|j}|jjdd|_ d|kr”|d|_ n |jjj |_ |rÆ|jjj  |¡|jj |j¡n4| |¡}t|ƒræ|j |¡n|jjj |jj¡dS)NFÚlocalÚidsrÚ backlinks)rrZ use_latex_tocÚAttributeErrorr rrr!rr"Útoc_idr2Z toc_backlinksÚ attributesÚupdaterÚbuild_contentsÚlenZ replace_self)rZ toc_by_writerrr ÚcontentsrrrrXs,       zContents.applyrcCs8|d7}dd„|Dƒ}g}d}|jj dtj¡}xÒ|D]Ê}|d}| d¡} | |¡} tjd| žd|d diŽ} |j  | ¡} t  dd| ¡} t  d| ¡}|j d krÚ|  tj¡dkrÚ|j d krÆ| |d<n|j d krÚ|j|d<||krö| ||¡}||7}| |¡q6W|r0tjd|žŽ}| r,|d  d¡|SgSdS)Nr cSsg|]}t|tjƒr|‘qSr)r!rr")Ú.0Úsectrrrú xsz+Contents.build_contents..rrr r Zrefidr1)ÚentryÚtopr=r>rzauto-toc)r r )r )r rrrrÚcopy_and_filterrÚ referencerZset_idZ paragraphZ list_itemr2Z next_noder4r7ÚappendZ bullet_list)rr'ÚlevelÚsectionsÚentriesZautonumrr"r)r Z entrytextr@Zref_idr=ÚitemZsubsectsr9rrrr7vs<           zContents.build_contentscCst|jƒ}| |¡| ¡S)z@Return a copy of a title, with references, images, etc. removed.)ÚContentsFilterrZ walkaboutÚget_entry_text)rr'Zvisitorrrrr?—s  zContents.copy_and_filterN)r)r*r+r,r-r.rr7r?rrrrr/Fs  !r/c@sDeZdZdd„Zdd„Zdd„Zdd„Zd d „ZeZeZ eZ eZ d S) rFcCs | ¡jS)N)Z get_tree_copyÚchildren)rrrrrG szContentsFilter.get_entry_textcCs tj‚dS)N)rÚSkipNode)rr'rrrÚvisit_citation_reference£sz'ContentsFilter.visit_citation_referencecCs tj‚dS)N)rrI)rr'rrrÚvisit_footnote_reference¦sz'ContentsFilter.visit_footnote_referencecCs*| d¡r |j t |d¡¡tj‚dS)NZalt)ÚhasattrrrArZTextrI)rr'rrrÚ visit_image©s zContentsFilter.visit_imagecCs tj‚dS)N)rZ SkipDeparture)rr'rrrÚ ignore_node_but_process_children®sz/ContentsFilter.ignore_node_but_process_childrenN) r*r+r,rGrJrKrMrNZvisit_interpretedZvisit_problematicZvisit_referenceZ visit_targetrrrrrFžsrF)r-Z __docformat__ÚrerZdocutilsrrZdocutils.transformsrrrr/ZTreeCopyVisitorrFrrrrÚs4X