docutils.transforms.references module
Transforms for resolving references.
- class PropagateTargets(document, startnode=None)[source]
Bases:
TransformPropagate empty internal targets to the next element.
Given the following nodes:
<target ids="internal1" names="internal1"> <target anonymous="1" ids="id1"> <target ids="internal2" names="internal2"> <paragraph> This is a test.
PropagateTargets propagates the ids and names of the internal targets preceding the paragraph to the paragraph itself:
<target refid="internal1"> <target anonymous="1" refid="id1"> <target refid="internal2"> <paragraph ids="internal2 id1 internal1" names="internal2 internal1"> This is a test.
- default_priority = 260
Numerical priority of this transform, 0 through 999 (override).
- class AnonymousHyperlinks(document, startnode=None)[source]
Bases:
TransformLink anonymous references to targets. Given:
<paragraph> <reference anonymous="1"> internal <reference anonymous="1"> external <target anonymous="1" ids="id1"> <target anonymous="1" ids="id2" refuri="http://external">
Corresponding references are linked via “refid” or resolved via “refuri”:
<paragraph> <reference anonymous="1" refid="id1"> text <reference anonymous="1" refuri="http://external"> external <target anonymous="1" ids="id1"> <target anonymous="1" ids="id2" refuri="http://external">
- default_priority = 440
Numerical priority of this transform, 0 through 999 (override).
- class IndirectHyperlinks(document, startnode=None)[source]
Bases:
TransformIndirect external references:
<paragraph> <reference refname="indirect external"> indirect external <target id="id1" name="direct external" refuri="http://indirect"> <target id="id2" name="indirect external" refname="direct 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):
<paragraph> <reference refname="indirect external"> indirect external <target id="id1" name="direct external" refuri="http://indirect"> <target id="id2" name="indirect external" refuri="http://indirect">
Once the attribute is migrated, the preexisting “refname” attribute is dropped.
Indirect internal references:
<target id="id1" name="final target"> <paragraph> <reference refname="indirect internal"> indirect internal <target id="id2" name="indirect internal 2" refname="final target"> <target id="id3" name="indirect internal" refname="indirect internal 2">
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:
<target id="id1" name="final target"> <paragraph> <reference refid="id1"> indirect internal <target id="id2" name="indirect internal 2" refid="id1"> <target id="id3" name="indirect internal" refid="id1">
- default_priority = 460
Numerical priority of this transform, 0 through 999 (override).
- class ExternalTargets(document, startnode=None)[source]
Bases:
TransformGiven:
<paragraph> <reference refname="direct external"> direct external <target id="id1" name="direct external" refuri="http://direct">
The “refname” attribute is replaced by the direct “refuri” attribute:
<paragraph> <reference refuri="http://direct"> direct external <target id="id1" name="direct external" refuri="http://direct">
- default_priority = 640
Numerical priority of this transform, 0 through 999 (override).
- class InternalTargets(document, startnode=None)[source]
Bases:
Transform- default_priority = 660
Numerical priority of this transform, 0 through 999 (override).
- resolve_reference_ids(target)[source]
Given:
<paragraph> <reference refname="direct internal"> direct internal <target id="id1" name="direct internal">
The “refname” attribute is replaced by “refid” linking to the target’s “id”:
<paragraph> <reference refid="id1"> direct internal <target id="id1" name="direct internal">
- class Footnotes(document, startnode=None)[source]
Bases:
TransformAssign numbers to autonumbered footnotes, and resolve links to footnotes, citations, and their references.
Given the following
documentas input:<document> <paragraph> A labeled autonumbered footnote reference: <footnote_reference auto="1" id="id1" refname="footnote"> <paragraph> An unlabeled autonumbered footnote reference: <footnote_reference auto="1" id="id2"> <footnote auto="1" id="id3"> <paragraph> Unlabeled autonumbered footnote. <footnote auto="1" id="footnote" name="footnote"> <paragraph> 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, alabelelement is added to the beginning of thefootnote, and reference text to thefootnote_reference.The transformed result will be:
<document> <paragraph> A labeled autonumbered footnote reference: <footnote_reference auto="1" id="id1" refid="footnote"> 2 <paragraph> An unlabeled autonumbered footnote reference: <footnote_reference auto="1" id="id2" refid="id3"> 1 <footnote auto="1" id="id3" backrefs="id2"> <label> 1 <paragraph> Unlabeled autonumbered footnote. <footnote auto="1" id="footnote" name="footnote" backrefs="id1"> <label> 2 <paragraph> Labeled autonumbered footnote.
Note that the footnotes are not in the same order as the references.
The labels and reference text are added to the auto-numbered
footnoteandfootnote_referenceelements. Footnote elements are backlinked to their references via “refids” attributes. References are assigned “id” and “refid” attributes.After adding labels and reference text, the “auto” attributes can be ignored.
- default_priority = 620
Numerical priority of this transform, 0 through 999 (override).
- autofootnote_labels = None
Keep track of unlabeled autonumbered footnotes.
- symbols = ['*', '†', '‡', '§', '¶', '#', '♠', '♥', '♦', '♣']
- number_footnotes(startnum)[source]
Assign numbers to autonumbered footnotes.
For labeled autonumbered footnotes, copy the number over to corresponding footnote references.
- class Substitutions(document, startnode=None)[source]
Bases:
TransformGiven the following
documentas input:<document> <paragraph> The <substitution_reference refname="biohazard"> biohazard symbol is deservedly scary-looking. <substitution_definition name="biohazard"> <image alt="biohazard" uri="biohazard.png">
The
substitution_referencewill simply be replaced by the contents of the correspondingsubstitution_definition.The transformed result will be:
<document> <paragraph> The <image alt="biohazard" uri="biohazard.png"> symbol is deservedly scary-looking. <substitution_definition name="biohazard"> <image alt="biohazard" uri="biohazard.png">
- default_priority = 220
The Substitutions transform has to be applied very early, before docutils.transforms.frontmatter.DocTitle and others.
- class TargetNotes(document, startnode)[source]
Bases:
TransformCreates a footnote for each external target in the text, and corresponding footnote references after each reference.
- default_priority = 540
The TargetNotes transform has to be applied after IndirectHyperlinks but before Footnotes.
- class DanglingReferences(document, startnode=None)[source]
Bases:
TransformCheck for dangling references (incl. footnote & citation) and for unreferenced targets.
- default_priority = 850
Numerical priority of this transform, 0 through 999 (override).