ó V!¶\c@sIdZdZddlZddlZddlmZmZddlmZm Z de fd„ƒYZ de fd „ƒYZ d e fd „ƒYZ d e fd „ƒYZ de fd„ƒYZde fd„ƒYZdefd„ƒYZde fd„ƒYZde fd„ƒYZde fd„ƒYZdejfd„ƒYZdS(s& Transforms for resolving references. treStructuredTextiÿÿÿÿN(tnodestutils(tTransformErrort TransformtPropagateTargetscBseZdZdZd„ZRS(s} 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. icCsxþ|jjtjƒD]ç}t|jtjƒs|jdƒs|jdƒs|jdƒrdqnt|ƒdks‚t dƒ‚|j dt ƒ}|dk rt|tj ƒ rÆt|tjƒ sØt|tjƒr|dj|dƒ|dj|dƒt|d ƒsi|_nt|d ƒs8i|_nx/|dD]#}||jj|<||j| internal external Corresponding references are linked via "refid" or resolved via "refuri":: text external i¸c Cség}g}x<|jjtjƒD]%}|jdƒr"|j|ƒq"q"Wx<|jjtjƒD]%}|jdƒra|j|ƒqaqaWt|ƒt|ƒkr>|jjj dt|ƒt|ƒfƒ}|jj |ƒ}xX|D]P}tj |j |j d|ƒ}|jj |ƒ}|j |ƒ|j|ƒqæWdSx¤t||ƒD]“\}} d| _x{trà| jdƒr–| d|d 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 iÌcCsAx:|jjD],}|js,|j|ƒn|j|ƒq WdS(N(Rtindirect_targetsR6tresolve_indirect_targettresolve_indirect_references(R R((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyR#Ðs cCsÉ|jdƒ}|dkr(|d}nV|jjj|ƒ}|s~x4|jjjD]}||ƒrSPqSqSW|j|ƒdS|jj|}|jd|ƒt |t j ƒr|j r|j dƒrt |dƒré|j|ƒdSd|_|j|ƒ|`n|j dƒr>|d|dwhich is a duplicate, and cannot be used as a unique referenceswhich does not exist(RRDtindirect_target_error(R R((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyRGscCs|j|dƒdS(Nsforming a circular reference(RM(R R((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyRI sc Csed}g}|dr+d|dd}nx1|dD]%}|j|jjj|gƒƒq6Wx1|dD]%}|j|jjj|gƒƒqjW|dr¶|d|dd7}n|jjjd||d|fd |ƒ}|jj|ƒ}xatj |ƒD]P} t j | j | j d |ƒ} |jj| ƒ} |j | ƒ| j| ƒqWd |_dS( NtR s"%s" iR s (id="%s")s7Indirect hyperlink target %s refers to target "%s", %s.Rt base_nodeRi(RRtrefnamesR+trefidsR-R.R/RtuniqRR0R1R2R3R6( R Rt explanationtnamingtreflistR"R!R:R;R<R=R>((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyRM s* ##   c Cs¾|jdƒr$d}|jj}n"|jdƒrBd}d}ndS||}x²|dD]¦}|jjj|gƒ}|r’|jd|ƒnxl|D]d}|jr®q™n|d=|||<|rÒ||ƒnd|_t|t j ƒr™|j |ƒq™q™Wq[Wx²|dD]¦}|jj j|gƒ}|rG|jd|ƒnxl|D]d}|jrcqNn|d=|||<|r‡||ƒnd|_t|t j ƒrN|j |ƒqNqNWqWdS( NRRR R"RiR R!( RRRRRPR+RHR6RRRRBRQ( R Rtattnamet call_methodtattvalR"RUR<R!((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyRB$sH            ( R$R%R&R'R#RARGRIRMRB(((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyR?šs2  -   tExternalTargetscBseZdZdZd„ZRS(s¸ Given:: direct external The "refname" attribute is replaced by the direct "refuri" attribute:: direct external i€cCsÀx¹|jjtjƒD]¢}|jdƒr|d}x€|dD]q}|jjj|gƒ}|rw|jd|ƒnx7|D]/}|jr“q~n|d=||d direct internal The "refname" attribute is replaced by "refid" linking to the target's "id":: direct internal R R"RRiN(RRDR+RPRHR6(R RR"RRUR<((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyR[ys   (R$R%R'R#R[(((sB/tmp/pip-install-usGedi/docutils/docutils/transforms/references.pyRZps t Footnotesc BsteZdZdZdZdddddddd d d g Zd „Zd „Zd„Z d„Z d„Z d„Z RS(sè 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