z]c@sdZdZddlZddlZddlmZmZddlmZm Z de fdYZ de fd YZ d ej fd YZ dS( s' Transforms related to document parts. treStructuredTextiN(tnodestutils(tTransformErrort TransformtSectNumcBs,eZdZdZdZdddZRS(sS 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|jjjdd|_|jjjdd|_|jjjdd|_|jjjdd|_|jjj |j|j j j r|jdkrt j|_n|j|j nH|j|j j _|j|j j _|j|j j _|j|j j _dS(Ntdepthtstartitprefixttsuffix(t startnodetdetailstgettNonetmaxdeptht startvalueRR tparenttremovetdocumenttsettingst sectnum_xformtsystmaxinttupdate_section_numberst sectnum_deptht sectnum_starttsectnum_prefixtsectnum_suffix(tself((s;/tmp/pip-build-kBFYxq/docutils/docutils/transforms/parts.pytapply sic Cs|d7}|rd}n |j}x|D]}t|tjr)|t|f}|d}tjd|jdj||jd ddg}|j d|d|d <||j kr|j |||n|d7}q)q)WdS( NiiR t.u itclassestsectnumtautou   ( Rt isinstanceRtsectiontstrt generatedRtjoinR tinsertRR( RtnodeRRR!tchildtnumbersttitleR&((s;/tmp/pip-build-kBFYxq/docutils/docutils/transforms/parts.pyR0s"     !  ((t__name__t __module__t__doc__tdefault_priorityRR(((s;/tmp/pip-build-kBFYxq/docutils/docutils/transforms/parts.pyRs  tContentscBs2eZdZdZdZddZdZRS(s 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"). icCs\y|jjj}Wntk r,t}nX|jj}d|kr|jjj}x=t|t j pxt|t js|j}qWWn |j}|jjdd|_ d|kr|d|_ n|jjj |_ |r|jjjj||jjj|jnJ|j|}t|r<|jj|n|jjjj|jjdS(Ntlocaltidsit backlinks(RRt use_latex_toctAttributeErrortFalseR R RR#RR$ttoc_idR4t toc_backlinkst attributestupdateRtbuild_contentstlent replace_self(Rt toc_by_writerR R tcontents((s;/tmp/pip-build-kBFYxq/docutils/docutils/transforms/parts.pyRXs,       icCs|d7}g|D]}t|tjr|^q}g}d}|jjjdtj}x/|D]'}|d} | jd} |j| } tj ddd|dd| } |j j | } tj dd| }tj d|}|jd krR| jtj dkrR|jdkr0| | ds  4X