Qc@sIdZdZddlZddlZddlmZmZddlmZm Z de fdYZ de fd YZ d e fd YZ d e fd YZ de fdYZde fdYZdefdYZde fdYZde fdYZde fdYZdejfdYZdS(s& Transforms for resolving references. treStructuredTextiN(tnodestutils(tTransformErrort TransformtPropagateTargetscBseZdZdZdZRS(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. ic Csx|jjtjD]}t|jtjs|jds|jds|jdrdqnt|dkst d|j dt }|dk rt|tj  rt|tj st|tjr|dj|d|dj|dt|d si|_nt|d s8i|_nx/|dD]#}||jj|<||j| internal external Corresponding references are linked via "refid" or resolved via "refuri":: text external ic Csg}g}x<|jjtjD]%}|jdr"|j|q"q"Wx<|jjtjD]%}|jdra|j|qaqaWt|t|kr>|jjj dt|t|f}|jj |}xX|D]P}tj |j |j d|}|jj |}|j ||j|qWdSxt||D]\}} d| _x{tr| jdr| 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 icCsAx:|jjD],}|js,|j|n|j|q WdS(N(Rtindirect_targetsR6tresolve_indirect_targettresolve_indirect_references(R R((sB/usr/lib/python2.7/site-packages/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 drt |dr|j|dSd|_|j||`n|j dr>|d|dwhich is a duplicate, and cannot be used as a unique referenceswhich does not exist(RRDtindirect_target_error(R R((sB/usr/lib/python2.7/site-packages/docutils/transforms/references.pyRGscCs|j|ddS(Nsforming a circular reference(RM(R R((sB/usr/lib/python2.7/site-packages/docutils/transforms/references.pyRI sc Csed}g}|dr+d|dd}nx1|dD]%}|j|jjj|gq6Wx1|dD]%}|j|jjj|gqjW|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/usr/lib/python2.7/site-packages/docutils/transforms/references.pyRM s* ##   c Cs|jdr$d}|jj}n"|jdrBd}d}ndS||}x|dD]}|jjj|g}|r|jd|nxl|D]d}|jrqn|d=|||<|r||nd|_t|t j r|j |qqWq[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/usr/lib/python2.7/site-packages/docutils/transforms/references.pyRB$sH            ( R$R%R&R'R#RARGRIRMRB(((sB/usr/lib/python2.7/site-packages/docutils/transforms/references.pyR?s2  -   tExternalTargetscBseZdZdZdZRS(s Given:: direct external The "refname" attribute is replaced by the direct "refuri" attribute:: direct external icCsx|jjtjD]}|jdr|d}x|dD]q}|jjj|g}|rw|jd|nx7|D]/}|jrq~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/usr/lib/python2.7/site-packages/docutils/transforms/references.pyR[ys   (R$R%R'R#R[(((sB/usr/lib/python2.7/site-packages/docutils/transforms/references.pyRZps t Footnotesc BsteZdZdZdZdddddddd d d g Zd Zd ZdZ dZ dZ dZ 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