o "5p`@sndZdZddlZddlZddlmZmZddlmZm Z Gddde Z Gdd d e Z Gd d d ej Z dS) z' Transforms related to document parts. reStructuredTextN)nodesutils)TransformError Transformc@s(eZdZdZdZ ddZd 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 rB|jdur:t j |_||j dS|j|j j _|j|j j _|j|j j _|j|j j _dS)Ndepthstartprefixsuffix) startnodedetailsgetmaxdepth startvaluer r parentremovedocumentsettings sectnum_xformsysmaxsizeupdate_section_numbers sectnum_depth sectnum_startsectnum_prefixsectnum_suffixselfr!;/usr/lib/python3/dist-packages/docutils/transforms/parts.pyapply s     z SectNum.applyr!rc Cs|d7}|r d}n|j}|D]A}t|tjrO|t|f}|d}tjd|jd||jddgd}| d|d|d<||j krK| ||||d7}qdS) Nr rr .u   sectnum)classesauto) r isinstancersectionstr generatedr joinr insertrr) r noder rr%childnumberstitler+r!r!r"r0s*   zSectNum.update_section_numbersN)r!r)__name__ __module__ __qualname____doc__default_priorityr#rr!r!r!r"rs  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"). icCst|jjdd}|jj}d|vr1|jjj}t|tjs0t|tjs0|j}t|tjs0t|tjr!n|j}|jjdd|_ d|vrG|d|_ n|jjj |_ |ra|jjj ||jj|jdS||}t|rr|j|dS|jjj|jjdS)N use_latex_tocFlocalidsr backlinks)getattrrrrrrr(rr)toc_idr; toc_backlinks attributesupdaterbuild_contentslen replace_self)r toc_by_writerrrcontentsr!r!r"r#Xs0       zContents.applyrcCs:|d7}dd|D}g}d}|jjdtj}|D]j}|d}|d} ||} tjddg| Rd|d di} |jj | d d } t dd| } t d| }|j d vrq| tjdurq|j d krg| |d<n |j dkrq|j|d<||kr|||}||7}||q|rtjdg|R}| r|dd|SgS)Nr cSsg|] }t|tjr|qSr!)r(rr)).0sectr!r!r" vsz+Contents.build_contents..rrr'r refidr:z toc-entry)suggested_prefix)entrytoprKrLr&zauto-toc)rrrrrcopy_and_filterr referencerset_id paragraph list_itemr; next_noder=rAappend bullet_list)r r.levelsectionsentriesautonumrr)r1r' entrytextrNref_idrKitemsubsectsrEr!r!r"rAtsB           zContents.build_contentscCst|j}|||S)z@Return a copy of a title, with references, images, etc. removed.)ContentsFilterr walkaboutget_entry_text)r r.visitorr!r!r"rMs  zContents.copy_and_filterN)r)r2r3r4r5r6r#rArMr!r!r!r"r7Fs   "r7c@s@eZdZddZddZddZddZd d ZeZeZ eZ d S) r]cCs |jSN) get_tree_copychildrenrr!r!r"r_s zContentsFilter.get_entry_textcCtjrarSkipNoder r.r!r!r"visit_citation_referencez'ContentsFilter.visit_citation_referencecCrdrarergr!r!r"visit_footnote_referenceriz'ContentsFilter.visit_footnote_referencecCs&|dr|jt|dtj)Nalt)hasattrrrSrTextrfrgr!r!r" visit_images zContentsFilter.visit_imagecCrdra)r SkipDeparturergr!r!r" ignore_node_but_process_childrenriz/ContentsFilter.ignore_node_but_process_childrenN) r2r3r4r_rhrjrnrpvisit_problematicvisit_reference visit_targetr!r!r!r"r]sr])r5 __docformat__rerdocutilsrrdocutils.transformsrrrr7TreeCopyVisitorr]r!r!r!r"s4W