o S_ߎ@sdZdZddlZddlZddlmZmZddlmZm Z Gddde Z Gdd d e Z Gd d d e Z Gd d d e Z Gddde ZGddde ZGdddeZGddde ZGddde ZGddde ZGdddejZdS)z& Transforms for resolving references. reStructuredTextN)nodesutils)TransformError Transformc@eZdZdZdZddZdS)PropagateTargetsa} Propagate empty internal targets to the next element. Given the following nodes:: This is a test. PropagateTargets propagates the ids and names of the internal targets preceding the paragraph to the paragraph itself:: This is a test. icCsf|jtjD]}t|jtjs|ds|ds|dr qt|dks*Jd|j dd}|durt|tj s@t|tj rFt|tjr|d |d|d  |d t|d s`i|_ t|d shi|_|dD] }||jj|<||j|<ql|d D]}||j |<q~|j t|d i|jt|d i|dd|d<g|d<g|d <|j|qdS) Nrefidrefurirefnamerz&error: block-level target has childrenT)ascendidsnamesexpect_referenced_by_nameexpect_referenced_by_id)documenttraversertarget isinstanceparent TextElementhasattrlen next_node Invisible Targetableextendrrr updategetattr note_refid)selfrridnamer#@/usr/lib/python3/dist-packages/docutils/transforms/references.pyapply*sR              zPropagateTargets.applyN__name__ __module__ __qualname____doc__default_priorityr%r#r#r#r$rs rc@r)AnonymousHyperlinksa Link anonymous references to targets. Given:: internal external Corresponding references are linked via "refid" or resolved via "refuri":: text external ic CsJg}g}|jtjD] }|dr||q |jtjD] }|dr+||qt|t|krj|jj dt|t|f}|j |}|D]}tj |j |j |d}|j |}| |||qKdSt||D]3\}} d| _ | dr| d|d<d|_n| ds|jj| d} qv| dd |d<|j| qodS) N anonymousz]Anonymous hyperlink mismatch: %s references but %s targets. See "backrefs" attribute for IDs.r Tr r r r)rrr referencegetappendrrreportererrorset_id problematic rawsource add_backref replace_selfzip referencedrresolvedr r) r anonymous_refsanonymous_targetsnodemsgmsgidrefprbprbidrr#r#r$r%rsT            zAnonymousHyperlinks.applyNr&r#r#r#r$r,Xs r,c@sDeZdZdZdZddZddZddZd d Zd d Z d dZ dS)IndirectHyperlinksaN a) Indirect external references:: indirect external The "refuri" attribute is migrated back to all indirect targets from the final direct target (i.e. a target not referring to another indirect target):: indirect external Once the attribute is migrated, the preexisting "refname" attribute is dropped. b) Indirect internal references:: indirect internal Targets which indirectly refer to an internal target become one-hop indirect (their "refid" attributes are directly set to the internal target's "id"). References which indirectly refer to an internal target become direct internal references:: indirect internal icCs,|jjD]}|js||||qdSN)rindirect_targetsr<resolve_indirect_targetresolve_indirect_referencesr rr#r#r$r%s   zIndirectHyperlinks.applycCsH|d}|dur|d}n|jj|}|s-|jjjD] }||r%dSq||dS|jj|}|j|dt|t j r]|j s]| dr]t |drS| |dSd|_|||`| drp|d|d<d|vro|d=n(| dr|d|d<|j|n|dr||d<|j|n||dS|dur|d=d|_ dS)Nr r r!multiply_indirectr/r r )r1rnameids transformerunknown_reference_resolversnonexistent_indirect_targetr note_referenced_byrrrr<rcircular_indirect_referencerLrHr)r rr reftarget_idresolver_function reftargetr#r#r$rHsT               z*IndirectHyperlinks.resolve_indirect_targetcCs0|d|jjvr||ddS||ddS)Nr z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)rrMindirect_target_errorrJr#r#r$rPsz.IndirectHyperlinks.nonexistent_indirect_targetcCs||ddS)Nzforming a circular reference)rVrJr#r#r$rR sz.IndirectHyperlinks.circular_indirect_referencec Csd}g}|drd|dd}|dD] }||jj|gq|dD] }||jj|gq&|drB|d|dd7}|jjjd||d|f|d }|j|}t |D]} t j | j | j |d } |j| } | | | | q]d |_dS) Nrz"%s" rr z (id="%s")z7Indirect hyperlink target %s refers to target "%s", %s.r  base_noder.r/)rrrefnamesr1refidsr3r4r5runiqrr6r7r8r9r<) r r explanationnamingreflistr"r!r@rArBrCrDr#r#r$rV s2         z(IndirectHyperlinks.indirect_target_errorc Cs(|dr d}|jj}n |drd}d}ndS||}|dD]6}|jj|g}|r2|j|d|D]!}|jr:q4|d=|||<|rG||d|_t|tj rU| |q4q |dD]6}|jj |g}|rm|j|d|D]!}|jruqo|d=|||<|r||d|_t|tj r| |qoq[dS) Nr r rr"r r/r rK) rrrrZr1rQr<rrrrIr[) r rattname call_methodattvalr"r_rBr!r#r#r$rI$sR           z.IndirectHyperlinks.resolve_indirect_referencesN) r'r(r)r*r+r%rHrPrRrVrIr#r#r#r$rEs2- rEc@r)ExternalTargetsa Given:: direct external The "refname" attribute is replaced by the direct "refuri" attribute:: direct external icCs~|jtjD]5}|dr<|d}|dD]%}|jj|g}|r(|j|d|D]}|jr0q*|d=||d<d|_q*qqdS)Nr rr`r r/) rrrrrrZr1rQr<)r rr r"r_rBr#r#r$r%`s    zExternalTargets.applyNr&r#r#r#r$rdLs rdc@s eZdZdZddZddZdS)InternalTargetsicCs6|jtjD]}|ds|ds||qdS)Nr r )rrrrrresolve_reference_idsrJr#r#r$r%ts  zInternalTargets.applycCsj|dD].}|jj|}|jj|g}|r|j|d|D]}|jr%q|r.|d=||d<d|_qqdS)a Given:: direct internal The "refname" attribute is replaced by "refid" linking to the target's "id":: direct internal rr`r r r/N)rrMr1rZrQr<)r rr"r r_rBr#r#r$rfys  z%InternalTargets.resolve_reference_idsN)r'r(r)r+r%rfr#r#r#r$reps rec@sReZdZdZdZdZ gdZddZddZd d Z d d Z d dZ ddZ dS) Footnotesa Assign numbers to autonumbered footnotes, and resolve links to footnotes, citations, and their references. Given the following ``document`` as input:: A labeled autonumbered footnote referece: An unlabeled autonumbered footnote referece: Unlabeled autonumbered footnote. Labeled autonumbered footnote. Auto-numbered footnotes have attribute ``auto="1"`` and no label. Auto-numbered footnote_references have no reference text (they're empty elements). When resolving the numbering, a ``label`` element is added to the beginning of the ``footnote``, and reference text to the ``footnote_reference``. The transformed result will be:: A labeled autonumbered footnote referece: 2 An unlabeled autonumbered footnote referece: 1