U C^ @sndZdZddlZddlZddlmZmZddlmZm Z Gddde Z Gdd d e Z Gd d d ej Z dS) z' Transforms related to document parts. ZreStructuredTextN)nodesutils)TransformError Transformc@s&eZdZdZdZddZd ddZd 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. icCs|jjdd|_|jjdd|_|jjdd|_|jjdd|_|jj|j|j j j r|jdkrtt j |_||j n0|j|j j _|j|j j _|j|j j _|j|j j _dS)Ndepthstartprefixsuffix) startnodedetailsgetmaxdepth startvaluer r parentremovedocumentsettingsZ sectnum_xformsysmaxsizeupdate_section_numbersZ sectnum_depthZ sectnum_startZsectnum_prefixZsectnum_suffixselfr?/tmp/pip-install-6_kvzl1k/docutils/docutils/transforms/parts.pyapply s     z SectNum.applyrrc Cs|d7}|rd}n|j}|D]}t|tjr|t|f}|d}tjd|jd||jddgd}| d|d|d<||j kr| ||||d7}qdS) Nr rr .u   sectnum)classesauto) r isinstancersectionstr generatedr joinr insertrr) rnoder rrchildZnumberstitler%rrrr0s(   zSectNum.update_section_numbersN)rr)__name__ __module__ __qualname____doc__default_priorityrrrrrrrs rc@s.eZdZdZdZddZd ddZdd 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"). icCsz|jjj}Wntk r&d}YnX|jj}d|krd|jjj}t|tj sjt|tjsj|j}qBn|j}|jjdd|_ d|kr|d|_ n |jjj |_ |r|jjj ||jj|jn4||}t|r|j|n|jjj|jjdS)NFlocalidsr backlinks)rrZ use_latex_tocAttributeErrorr rrr"rr#toc_idr3Z toc_backlinks attributesupdaterbuild_contentslenZ replace_self)rZ toc_by_writerrr contentsrrrrXs.        zContents.applyrcCs4|d7}dd|D}g}d}|jjdtj}|D]}|d}|d} ||} tjd| d|d di} |j | } t dd| } t d| }|j d kr| tjdkr|j d kr| |d<n|j d kr|j|d<||kr|||}||7}||q4|r,tjd|}| r(|d d|SgSdS)Nr cSsg|]}t|tjr|qSr)r"rr#).0sectrrr xs z+Contents.build_contents..rrr!r Zrefidr2)entrytopr>r?r zauto-toc)r r )r )r rrrrcopy_and_filterr referencerZset_idZ paragraphZ list_itemr3Z next_noder5r8appendZ bullet_list)rr(levelsectionsentriesZautonumrr#r*r!Z entrytextrAZref_idr>itemZsubsectsr:rrrr8vs@           zContents.build_contentscCst|j}|||S)z@Return a copy of a title, with references, images, etc. removed.)ContentsFilterrZ walkaboutget_entry_text)rr(Zvisitorrrrr@s  zContents.copy_and_filterN)r)r+r,r-r.r/rr8r@rrrrr0Fs  !r0c@s@eZdZddZddZddZddZd d ZeZeZ eZ d S) rGcCs |jSN)Z get_tree_copychildrenrrrrrHszContentsFilter.get_entry_textcCs tjdSrIrSkipNoderr(rrrvisit_citation_referencesz'ContentsFilter.visit_citation_referencecCs tjdSrIrKrMrrrvisit_footnote_referencesz'ContentsFilter.visit_footnote_referencecCs*|dr |jt|dtjdS)NZalt)hasattrrrBrZTextrLrMrrr visit_images zContentsFilter.visit_imagecCs tjdSrI)rZ SkipDeparturerMrrr ignore_node_but_process_childrensz/ContentsFilter.ignore_node_but_process_childrenN) r+r,r-rHrNrOrQrRZvisit_problematicZvisit_referenceZ visit_targetrrrrrGsrG)r.Z __docformat__rerZdocutilsrrZdocutils.transformsrrrr0ZTreeCopyVisitorrGrrrrs4X