
    k7i8                    P   S r SSKJr  SrSSKJrJr  SSKJr   " S S\5      r	 " S S	\5      r
 " S
 S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\R*                  5      rg)z&
Transforms for resolving references.
    )annotationsreStructuredText)nodesutils)	Transformc                  &    \ rS rSrSrSrSS jrSrg)PropagateTargets   aC  
Propagate 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.
i  c                   U R                   R                  [        R                  5       GH  n[	        UR
                  [        R                  5      (       dB  UR                  S5      (       d,  UR                  S5      (       d  UR                  S5      (       a  Mq  [        U5      S:X  d   S5       eUR                  SS9n[	        U[        R                  5      (       a1  UR                  SSS	9n[	        U[        R                  5      (       a  M1  UbN  [	        U[        R                  [        R                  45      (       a"  [	        U[        R                  5      (       d  GM:  US
   R                  US
   5        US   R                  US   5        [        US5      (       d  0 Ul        [        US5      (       d  0 Ul        US
    H)  nX R                   R                   U'   XR                  U'   M+     US    H  nXR                  U'   M     UR                  R#                  [%        US0 5      5        UR                  R#                  [%        US0 5      5        [	        UR
                  [        R&                  5      (       a=  [	        U[        R(                  5      (       a  UR
                  R+                  U5        GM  US
   S   US'   / US
'   / US'   U R                   R-                  U5        GM     g )Nrefidrefurirefnamer   z&error: block-level target has childrenT)ascendF)r   descendidsnamesexpect_referenced_by_nameexpect_referenced_by_id)documentfindallr   target
isinstanceparentTextElementhasattrlen	next_nodesystem_message	Invisible
Targetableextendr   r   r   updategetattrfigurecaptionremove
note_refid)selfr   r   idnames        X/home/james-whalen/.local/lib/python3.13/site-packages/docutils/transforms/references.pyapplyPropagateTargets.apply*   sm   mm++ELL9F6==%*;*;<<NN7++v~~h/G/G~~i00v;!#M%MM#(((5IY(<(<==%//tU/K	 Y(<(<== !i%//5;K;K)LMM"9ell;;e##F5M2g%%fWo69&ABB68	39&?@@46	1Um(1!!"% 9?11"5 $ w<B33D9 ( //66 ;R@B--44 92>@ &--66:u}}<. <.$$V, %UmA.F7OF5M F7OMM$$V,i :     NreturnNone__name__
__module____qualname____firstlineno____doc__default_priorityr,   __static_attributes__r/   r.   r+   r	   r	      s    * 5-r.   r	   c                  &    \ rS rSrSrSrSS jrSrg)AnonymousHyperlinksb   aa  
Link 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">
i  c                   U R                   R                  [        R                  5       Vs/ s H  nUR	                  S5      (       d  M  UPM     nnU R                   R                  [        R
                  5       Vs/ s H  nUR	                  S5      (       d  M  UPM     nn[        U5      [        U5      :w  a  U R                   R                  R                  S[        U5      < S[        U5      < S35      nU R                   R                  U5      nU Hj  n[        R                  " UR                  UR                  US9nU R                   R                  U5      nUR                  U5        UR                  U5        Ml     g [        X#5       H  u  piUR                  S5      (       d  UR                  S5      (       a  M3  SU	l         U	R                  S5      (       a  U	S   US'   SUl        Mb  U	S	   (       d  U R                   R$                  U	S      n	MP  U	S	   S
   US'   U R                   R'                  U5        M     g s  snf s  snf )N	anonymouszAnonymous hyperlink mismatch: z references but z+ targets.
See "backrefs" attribute for IDs.r   r   r   Tr   r   )r   r   r   	referencegetr   r   reportererrorset_idproblematic	rawsourceadd_backrefreplace_selfzipr   
referencedresolvedr   r'   )
r(   nodeanonymous_refsanonymous_targetsmsgmsgidrefprbprbidr   s
             r+   r,   AnonymousHyperlinks.apply|   s   !]]225??C&CTxx$ C 	 & "]]225<<@&@Txx$ @ 	 & ~#&7"88--((.. (#.?*@BCC MM((-E%''mmS]]%A,,S1&  % & ~AKC{{7##s{{8'<'< $F>>(++$*8$4CM#'CL!%=!%!2!26'?!C #)%=#3CLMM,,S1! B'&&s   I
I=IIr/   Nr0   r3   r/   r.   r+   r<   r<   b   s    , $r.   r<   c                  X    \ rS rSrSrSrSS jrSS jrSS jrSS jr	SS jr
SS	 jrS
rg)IndirectHyperlinks   a  
a) Indirect external references::

       <paragraph>
           <reference refname="indirect-external">
               indirect external
       <target ids="id1" names="direct-external"
           refuri="http://indirect">
       <target ids="id2" names="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 ids="id1" names="direct-external"
           refuri="http://indirect">
       <target ids="id2" names="indirect-external"
           refuri="http://indirect">

   Once the attribute is migrated, the preexisting "refname" attribute
   is dropped.

b) Indirect internal references::

       <target ids="id1" names="final-target">
       <paragraph>
           <reference refname="indirect-internal">
               indirect internal
       <target ids="id2" names="indirect-internal-2"
           refname="final target">
       <target ids="id3" names="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 ids="id1" names="final-target">
       <paragraph>
           <reference refid="id1">
               indirect internal
       <target ids="id2" names="indirect-internal-2" refid="id1">
       <target ids="id3" names="indirect-internal" refid="id1">
i  c                    U R                   R                   H6  nUR                  (       d  U R                  U5        U R	                  U5        M8     g N)r   indirect_targetsrL   resolve_indirect_targetresolve_indirect_referencesr(   r   s     r+   r,   IndirectHyperlinks.apply   s9    mm44F??,,V4,,V4 5r.   c                   UR                  S5      nUc  US   nOtU R                  R                  R                  U5      nU(       dH  U R                  R                  R                   H  nU" U5      (       d  M    g    U R                  U5        g U R                  R                  U   nUR                  US9  [        U[        R                  5      (       ad  UR                  (       dS  UR                  S5      (       a=  [        US5      (       a  U R                  U5        g SUl        U R                  U5        U?UR                  S5      (       a  US   US'   SU;   a  US	 OvUR                  S5      (       a$  US   US'   U R                  R!                  U5        O<US   (       a   X1S'   U R                  R!                  U5        OU R                  U5        g Ub  US	 SUl        g )	Nr   r   r)   multiply_indirect   r   r   T)rB   r   nameidstransformerunknown_reference_resolversnonexistent_indirect_targetr   note_referenced_byr   r   r   rL   r   circular_indirect_referencerb   r\   r'   )r(   r   r   reftarget_idresolver_function	reftargets         r+   r\   *IndirectHyperlinks.resolve_indirect_target   s   **Y'?!'?L==0044W=L 11MM &(00  N 44V<MM%%l3	$$$5y%,,//&&!!),,v233008'(F$((3(X&&(2F8& 7Ow'''0F7OMM$$V,".w((0008y!r.   c                    US   U R                   R                  ;   a  U R                  US5        g U R                  US5        g )Nr   z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)r   rd   indirect_target_errorr^   s     r+   rg   .IndirectHyperlinks.nonexistent_indirect_target  sC    ) 5 55&&v 0N O &&v/EFr.   c                (    U R                  US5        g )Nzforming a circular reference)ro   r^   s     r+   ri   .IndirectHyperlinks.circular_indirect_reference  s    ""6+IJr.   c           	        Sn/ nUS   (       a  SUS   S   -  nUS    H8  nUR                  U R                  R                  R                  U/ 5      5        M:     US    H8  nUR                  U R                  R                  R                  U/ 5      5        M:     US   (       a  USUS   S   -  -  nU R                  R
                  R                  SU< SUS	   < S
U< S3US9nU R                  R                  U5      n[        R                  " U5       Hj  n	[        R                  " U	R                  U	R                  US9n
U R                  R                  U
5      nUR                  U5        U	R                  U
5        Ml     SUl        g )N r   z"%s" r   r   z	(id="%s")zIndirect hyperlink target z refers to target "r   z", .	base_noder@   T)r!   r   refnamesrB   refidsrC   rD   rE   r   uniqr   rF   rG   rH   rI   rL   )r(   r   explanationnamingreflistr*   r)   rP   rQ   rR   rS   rT   s               r+   ro   (IndirectHyperlinks.indirect_target_error  sZ   '?vgq11F7ODNN4==1155dB?@ $-BNN4==//33B;<  %=kF5M!$444Fmm$$**	*K9DJ + L $$S)::g&C##--e=CMM((-EOOE"S! ' r.   c                n   UR                  S5      (       a  SnU R                  R                  nOUR                  S5      (       a  SnS nOg X   nUS    H  nU R                  R                  R	                  U/ 5      nU(       a  UR                  US9  U He  nUR                  (       a  M  US	 XGU'   U(       a  U" U5        SUl        [        U[        R                  5      (       d  MT  U R                  U5        Mg     M     US    H  nU R                  R                  R	                  U/ 5      nU(       a  UR                  US9  U He  nUR                  (       a  M  US	 XGU'   U(       a  U" U5        SUl        [        U[        R                  5      (       d  MT  U R                  U5        Mg     M     g )	Nr   r   r   r*   r   Tr   ra   )r   r   r'   rx   rB   rh   rL   r   r   r   r]   ry   )	r(   r   attnamecall_methodattvalr*   r}   rR   r)   s	            r+   r]   .IndirectHyperlinks.resolve_indirect_references,  sl   >>'""G--22K^^H%%GK7ODmm,,00r:G))t)4<<	N%G$#c5<<0044S9 	 $ -Bmm**..r26G))R)0<<L%G$#c5<<0044S9 	  r.   r/   Nr0   )r4   r5   r6   r7   r8   r9   r,   r\   rg   ri   ro   r]   r:   r/   r.   r+   rW   rW      s1    0d 5*XGK.%:r.   rW   c                  &    \ rS rSrSrSrSS jrSrg)ExternalTargetsiT  a  
Given::

    <paragraph>
        <reference refname="direct-external">
            direct external
    <target ids="id1" names="direct-external" refuri="http://direct">

The "refname" attribute is replaced by the direct "refuri" attribute::

    <paragraph>
        <reference refuri="http://direct">
            direct external
    <target ids="id1" names="direct-external" refuri="http://direct">
i  c                   U R                   R                  [        R                  5       H  nUR	                  S5      (       d  M  US   nUS    Hi  nU R                   R
                  R                  U/ 5      nU(       a  UR                  US9  U H$  nUR                  (       a  M  US	 X%S'   SUl        M&     Mk     M     g )Nr   r   r   r   T)	r   r   r   r   r   rx   rB   rh   rL   )r(   r   r   r*   r}   rR   s         r+   r,   ExternalTargets.applyh  s    mm++ELL9F~~h'')"7OD"mm4488rBG11t1<&<<$	N(.H'+  '	 , :r.   r/   Nr0   r3   r/   r.   r+   r   r   T  s      ,r.   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)InternalTargetsix  i  c                    U R                   R                  [        R                  5       HD  nUR	                  S5      (       a  M  UR	                  S5      (       a  M3  U R                  U5        MF     g )Nr   r   )r   r   r   r   r   resolve_reference_idsr^   s     r+   r,   InternalTargets.apply|  sJ    mm++ELL9F>>(++FNN74K4K**62 :r.   c                @   US    H  nU R                   R                  R                  U5      nU R                   R                  R                  U/ 5      nU(       a  UR	                  US9  U H+  nUR
                  (       a  M  U(       a  US	 X5S'   SUl        M-     M     g)a^  
Given::

    <paragraph>
        <reference refname="direct-internal">
            direct internal
    <target ids="id1" names="direct-internal">

The "refname" attribute is replaced by "refid" linking to the target's
"id"::

    <paragraph>
        <reference refid="id1">
            direct internal
    <target ids="id1" names="direct-internal">
r   r   r   r   TN)r   rd   rB   rx   rh   rL   )r(   r   r*   r   r}   rR   s         r+   r   %InternalTargets.resolve_reference_ids  s    " 7ODMM))--d3Emm,,00r:G))t)4<<I#(L#  $r.   r/   Nr0   )r4   r5   r6   r7   r9   r,   r   r:   r/   r.   r+   r   r   x  s    3
$r.   r   c                  b    \ rS rSrSrSrSr / SQrSS jrS r	SS jr
SS	 jrSS
 jrSS jrSrg)	Footnotesi  a2  
Assign numbers to autonumbered footnotes, and resolve links to footnotes,
citations, and their references.

Given the following ``document`` as input::

    <document>
        <paragraph>
            A labeled autonumbered footnote reference:
            <footnote_reference auto="1" ids="id1" refname="footnote">
        <paragraph>
            An unlabeled autonumbered footnote reference:
            <footnote_reference auto="1" ids="id2">
        <footnote auto="1" ids="id3">
            <paragraph>
                Unlabeled autonumbered footnote.
        <footnote auto="1" ids="footnote" names="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, a ``label`` element
is added to the beginning of the ``footnote``, and reference text
to the ``footnote_reference``.

The transformed result will be::

    <document>
        <paragraph>
            A labeled autonumbered footnote reference:
            <footnote_reference auto="1" ids="id1" refid="footnote">
                2
        <paragraph>
            An unlabeled autonumbered footnote reference:
            <footnote_reference auto="1" ids="id2" refid="id3">
                1
        <footnote auto="1" ids="id3" backrefs="id2">
            <label>
                1
            <paragraph>
                Unlabeled autonumbered footnote.
        <footnote auto="1" ids="footnote" names="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 ``footnote``
and ``footnote_reference`` elements.  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.
il  N)
*u   †u   ‡   §   ¶#u   ♠u   ♥u   ♦u   ♣c                    / U l         U R                  R                  nU R                  U5      U R                  l        U R	                  U5        U R                  5         U R                  5         g rZ   )autofootnote_labelsr   autofootnote_startnumber_footnotesnumber_footnote_referencessymbolize_footnotesresolve_footnotes_and_citations)r(   startnums     r+   r,   Footnotes.apply  sV    #% ==33+/+@+@+J(''1  ",,.r.   c                V   U R                   R                   GH  n [        U5      nUS-  nX0R                   R                  ;  a  OM,  UR	                  S[
        R                  " SU5      5        US    H  nU R                   R                  R                  U/ 5       H  nU[
        R                  " U5      -  nUR                  S5        [        US   5      [        US   5      s=:X  a  S:X  d   e   eUS   S   US'   UR                  US   S   5        U R                   R                  U5        SUl        M     M     US   (       a  GM6  US	   (       a  GMC  US   R                  U5        U R                   R!                  X"5        U R"                  R                  U5        GM     U$ )
z
Assign numbers to autonumbered footnotes.

For labeled autonumbered footnotes, copy the number over to
corresponding footnote references.
Trc   r   rt   r   r   r   r   dupnames)r   autofootnotesstrrd   insertr   labelfootnote_refsrB   Textdelattrr   rH   r'   rL   appendnote_explicit_targetr   )r(   r   footnoter   r*   rR   s         r+   r   Footnotes.number_footnotes  sr    33HHA 5 55	 
 OOAu{{2u56 )==66::4DC5::e,,CKK	*x/3s5z?GaGGGGG#+E?1#5CL((UA7MM,,S1#'CL E * G$$Xj-A-A!((/228F((//6' 4( r.   c           	     D   SnU R                   R                   H  nUR                  (       d  UR                  S5      (       a  M,   U R                  U   nU[        R                  " U5      -  nU R                   R                   U   nU R                   R"                  U   nXS'   U R                   R%                  U5        [        US   5      S:X  d   eUR                  US   S   5        SUl        US-  nM     g
! [
         Ga    [        U R                  5      nUS:  a  SOSnU R                   R                  R                  SU SU S3US	9nU R                   R                  U5      nU R                   R                  US
  H  nUR                  (       d  UR                  S5      (       a  M,  [        R                  " UR                  UR                  US9n	U R                   R                  U	5      n
UR                  U
5        UR                  U	5        M        g
f = f)z3Assign numbers to autonumbered footnote references.r   r   rc   srt   z0Too many autonumbered footnote references: only z corresponding footnotez available.rv   Nr   r@   r   T)r   autofootnote_refsrL   r   r   
IndexErrorr   rC   rD   rE   r   rF   rG   rH   rI   r   rd   r   r'   )r(   r   irR   r   nr   rP   rQ   rS   rT   r)   r   s                r+   r   $Footnotes.number_footnote_references  s   ==22C||s{{733003$ 5::e$$C&&u-B}}((,HLMM$$S)s5z?a'''  UA/CLFA= 3
  001q5Cbmm,,22""#$;A3kK$' 3 ) ,,S1==::12>C||s{{9'='= ++--eEC MM005EOOE*$$S) ? !s   C;;D HHc           	     &   / nU R                   R                   H  n[        U R                   R                  [	        U R
                  5      5      u  p4U R
                  U   US-   -  nUR                  U5        UR                  S[        R                  " SU5      5        U R                   =R                  S-  sl        U R                   R                  U5        M     SnU R                   R                   H  n U[        R                  " X   5      -  nU R                   R                  U   n[	        US	   5      S:X  d   eUS	   S   US'   U R                   R-                  U5        UR)                  US	   S   5        US-  nM     g! [         a    U R                   R                  R                  S[	        U5      -  US9nU R                   R                  U5      n	U R                   R                  US  H  nUR                   (       d  UR#                  S5      (       a  M,  [        R$                  " UR&                  UR&                  U	S9n
U R                   R                  U
5      nUR)                  U5        UR+                  U
5        M        gf = f)
z<Add symbols indexes to "[*]"-style footnotes and references.rc   r   rt   zOToo many symbol footnote references: only %s corresponding footnotes available.rv   Nr   r@   r   )r   symbol_footnotesdivmodsymbol_footnote_startr   symbolsr   r   r   r   rE   symbol_footnote_refsr   r   rC   rD   rL   r   rF   rG   rH   rI   r'   )r(   labelsr   repsindex	labeltextr   rR   rP   rQ   rS   rT   s               r+   r   Footnotes.symbolize_footnotes;  s)   66H !D!D!$T\\!24KDU+tax8IMM)$OOAu{{2y9:MM//14/MM  * 7 ==55Cuzz&),,  }}55a8Hx'1,,,#E?1-CLMM$$S)  UA/FA/ 6  mm,,22;=@[I # 3 % ,,S1====abAC||s{{7';'; ++--eEC MM005EOOE*$$S) B s   8FDJJc                   U R                   R                   HT  nUS    HH  nX R                   R                  ;   d  M  U R                   R                  U   nU R                  X5        MJ     MV     U R                   R                   HT  nUS    HH  nX R                   R
                  ;   d  M  U R                   R
                  U   nU R                  XC5        MJ     MV     g)zI
Link manually-labeled footnotes and citations to/from their
references.
r   N)r   	footnotesr   resolve_references	citationscitation_refs)r(   r   r   r}   citations        r+   r   )Footnotes.resolve_footnotes_and_citations`  s    
 //H!'*MM777"mm99%@G++H> + 0
 //H!'*MM777"mm99%@G++H> + 0r.   c                   [        US   5      S:X  d   eUS   S   nU H]  nUR                  (       a  M  UR                  S5        X4S'   [        US   5      S:X  d   eUR                  US   S   5        SUl        M_     SUl        g )Nr   rc   r   r   r   T)r   rL   r   rH   )r(   noter}   r)   rR   s        r+   r   Footnotes.resolve_referencesp  s    4;1$$$%[^C||KK	"Ls5z?a'''SZ]+CL  r.   )r   r0   )r4   r5   r6   r7   r8   r9   r   r   r,   r   r   r   r   r   r:   r/   r.   r+   r   r     s@    9v 9G"/:!F#J? r.   r   c                      \ rS rSrSrg)#CircularSubstitutionDefinitionErrori~  r/   N)r4   r5   r6   r7   r:   r/   r.   r+   r   r   ~  s    r.   r   c                  $    \ rS rSrSrSr S rSrg)Substitutionsi  a  
Given the following ``document`` as input::

    <document>
        <paragraph>
            The
            <substitution_reference refname="biohazard">
                biohazard
             symbol is deservedly scary-looking.
        <substitution_definition names="biohazard">
            <image alt="biohazard" uri="biohazard.png">

The ``substitution_reference`` will simply be replaced by the
contents of the corresponding ``substitution_definition``.

The transformed result will be::

    <document>
        <paragraph>
            The
            <image alt="biohazard" uri="biohazard.png">
             symbol is deservedly scary-looking.
        <substitution_definition names="biohazard">
            <image alt="biohazard" uri="biohazard.png">
   c           	     
   U R                   R                  nU R                   R                  n0 n[        U R                   R                  SS5      n[        U R                   R                  [        R                  5      5      nU GH1  nSnUS   nX;   a  Un	O"UR                  5       n
UR                  U
S 5      n	U	c(  U R                   R                  R                  SU-  US9nOIX   n[        UR                  5       5      U:  a(  U R                   R                  R                  SU	-  5      nU(       a  U R                   R                  U5      n[        R                   " UR"                  UR"                  US9nU R                   R                  U5      nUR%                  U5        UR'                  U5        GM5  UR(                  nUR+                  U5      nS	WR,                  ;   d  S
UR,                  ;   aG  US:  aA  [/        UUS-
     [        R0                  5      (       a  UUS-
     R3                  5       UUS-
  '   SUR,                  ;   d  S
UR,                  ;   aS  [        U5      US-   :  aA  [/        UUS-      [        R0                  5      (       a  UUS-      R5                  5       UUS-   '   UR7                  5       n UR                  [        R                  5       H_  nUUS   R                  5          nUUR9                  U/ 5      ;   a  [:        eUU   R=                  U	5        UUS'   UR=                  U5        Ma     UR'                  URF                  5        URF                   HG  n[/        U[        RH                  5      (       d  M$  SU;   d  M,  U R                   RK                  U5        MI     GM4     g ! [:         Gay    UR(                  n[/        U[        R>                  5      (       ak  U R                   R                  R                  S[        R@                  " UR"                  UR"                  5      URB                  US9nUR'                  U5        OUnURE                  S5      (       a  US   nURE                  S5      (       a  M  U R                   R                  R                  SU-  US9nU R                   R                  U5      n[        R                   " UR"                  UR"                  US9nU R                   R                  U5      nUR%                  U5        UR'                  U5         GM  f = f)Nline_length_limiti'  rt   r   z(Undefined substitution referenced: "%s".rv   z;Substitution definition "%s" exceeds the line-length-limit.r@   ltrimtrimr   rc   rtrimz
ref-originz*Circular substitution definition detected:)linerw   z2Circular substitution definition referenced: "%s".)&r   substitution_defssubstitution_namesr#   settingslistr   r   substitution_referencelowerrB   rC   rD   r   astextrE   rF   rG   rH   rI   r   r   
attributesr   r   rstriplstripdeepcopy
setdefaultr   r   substitution_definitionliteral_blockr   r   childrenReferentialnote_refname)r(   defsnormednestedr   
subreflistrR   rP   r   keynormed_namesubdefrQ   rS   rT   r   r   subdef_copy
nested_refnested_name
ref_originrM   s                         r+   r,   Substitutions.apply  s   }}..11#DMM$:$:$7@ $--//0L0LMN
CC)nG%mmojjd3{mm,,22@ +. 3 0 v}}'*;;--006624789C ,,S1''mmS]]%A,,S1&  %ZZFLL%E6,,,V...19F519,=,1JJ"8 "8(.uqy(9(@(@(BF519%6,,,V...K%!)+"6%!)#4ejjAA(.uqy(9(@(@(BF519% //+K!"-"5"544#6J"(I)>)D)D)F"GK"f&7&7R&HHAA;'..s3/2J|,%%j1#6@ [112 $,,dE$5$566 !D(2248 -[ d 7 fe&C&CDD--0066D++F,<,<,2,<,<>#[[F	 7 <C
 '', "%J$,,\::%/%=
 %,,\::--0066 ")*5? 7 AC !MM005E++s}}ECC MM005EOOE*$$S)/s   BN;;CT?B)T?>T?r/   Nr3   r/   r.   r+   r   r     s    4 >Z9r.   r   c                  8    \ rS rSrSrSr S	S jrS	S jrS rSr	g)
TargetNotesi  zv
Creates a footnote for each external target in the text, and corresponding
footnote references after each reference.
i  c                p    [         R                  " XUS9  UR                  R                  S/ 5      U l        g )N)	startnodeclass)r   __init__detailsrB   classes)r(   r   r   s      r+   r   TargetNotes.__init__
  s,    4Y? ((,,Wb9r.   c                   0 n/ nU R                   R                  [        R                  5       H  nUR	                  S5      (       d  M  US   n/ nU H8  nUR                  U R                   R                  R                  U/ 5      5        M:     U(       d  Mi  U R                  US   UU5      nUS   U;  d  M  XqUS   '   UR                  U5        M     U R                   R                  [        R                  5       Hm  nUR                  S5      (       d  M  UR	                  S5      (       d  M3  U R                  US   U/U5      nUS   U;  d  MU  XqUS   '   UR                  U5        Mo     U R                  R                  U5        g )Nr   r   r?   )r   r   r   r   r   r!   rx   rB   make_target_footnoter   rA   r   rI   )	r(   notesnodelistr   r   refsr*   r   rR   s	            r+   r,   TargetNotes.apply  sS   mm++ELL9F>>(++7OEDDMM2266tR@A 001A4168Hhu,*2fX&') :  ==((9C77;''{{8$$44S]SE5:<x=-+3#h-(OOH- : 	##H-r.   c           	     `   X;   a!  X1   n[        US   5      S:X  d   eUS   S   nO[        R                  " 5       nU R                  R	                  U5      nSU-   nSUS'   U/US'   [        R
                  " 5       nU[        R                  " SXS9-  nXG-  nU R                  R                  U5        U R                  R                  XD5        U GHY  n[        U[        R                  5      (       a  M%  [        R                  " USS9n	U	S	==   U R                  -  ss'   U R                  R                  U	5        U R                  R                  U	5        UR                  R!                  U5      S-   n
U	/n["        R$                  " U R                  R&                  5      (       dg  U R                  (       a0  UR)                  S[        R*                  " S
U R                  S95        O&UR)                  S[        R,                  " S
5      5        UR                  R)                  X5        GM\     U$ )Nr   rc   r   zTARGET_NOTE: autort   )r   )r   r   r    )textClasses)r   r   r   r   rE   	paragraphrA   note_autofootnoter   r   r   footnote_referencer   note_autofootnote_refnote_footnote_refr   r   r   get_trim_footnote_ref_spacer   r   inliner   )r(   r   r   r   r   footnote_namefootnote_idfootnote_paragraphrR   refnoder   r}   s               r+   r    TargetNotes.make_target_footnote-  s   ?}Hx()Q...$W-a0M~~'H--..x8K ,k9M HV!.HW!&!2%//"f"LL*HMM++H5MM..xBC#u||,,..}1MGI$,,.MM//8MM++G4JJ$$S)A-EiG44T]]5K5KLL<<NN5<<S$,,GI NN1ejjo6JJe-   r.   )r   Nr0   )
r4   r5   r6   r7   r8   r9   r   r,   r   r:   r/   r.   r+   r   r     s#    
 :
.<"r.   r   c                  &    \ rS rSrSrSrSS jrSrg)CitationReferencesR  zResolve <citation_references>.

The 'use_bibtex'__ configuration setting indicates that citation entries
are fetched from a BibTeX database by the backend (LaTeX).

__ https://docutils.sourceforge.io/docs/user/config.html#use-bibtex
i  c                   [        U R                  R                  S/ 5      (       d  g U R                  R                  [        R
                  5       H~  nUR                  (       d9  U R                  R                  R                  UR                  S5      5      (       a  MO  UR                  5       (       d  Mf  UR                  S5        SUl        M     g )N
use_bibtexr   T)r#   r   r   r   r   citation_referencerL   rd   rB   r   r   r(   rM   s     r+   r,   CitationReferences.apply_  s    t}}--|R@@MM))%*B*BCD
 }} 5 5 9 9$((9:M N N{{}}Y' $ Dr.   r/   Nr0   r3   r/   r.   r+   r  r  R  s     %r.   r  c                  &    \ rS rSrSrSrSS jrSrg)DanglingReferencesin  u  
Check for dangling references (incl. footnote & citation) and for
unreferenced targets.

Provisional : pending deprecation
  Docutils readers will add separate transforms for resolving
  refnames to refids and for reporting unresolved references
  instead of this transform (to make space for reference-resolving
  transforms added by extensions or applications) in Docutils 1.0.
  This transform will be removed in Docutils 2.0.
r  c                   [        U R                  U R                  R                  R                  5      nU R                  R	                  U5        U R                  R                  [        R                  5       H  nUR                  (       a  M  UR                  S5      (       a  M.  US   (       a	  US   S   nOUS   (       a	  US   S   nOUS   nU R                  R                  R                  SU-  US9  M     g )Nr?   r   r   r   r   z(Hyperlink target "%s" is not referenced.rv   )DanglingReferencesVisitorr   re   rf   walkr   r   r   rK   rB   rC   info)r(   visitorr   r|   s       r+   r,   DanglingReferences.apply~  s    +MMMM%%AAC 	7# mm++ELL9F$$$::k**
 '?#G_Q/FE]#E]1-F $G_F&&++>(. , 0! :r.   r/   Nr0   r3   r/   r.   r+   r  r  n  s    
 0r.   r  c                  >    \ rS rSrSrSS jrSS jrSS jr\=rr	Sr
g)	r  i  u   Provisional : pending deprecation

This auxiliary class is used by the `DanglingReferences` transform
which will no longer be used in Docutils 1.0.
It will be removed in Docutils 2.0.
c                Z    [         R                  R                  X5        Xl        X l        g rZ   )r   SparseNodeVisitorr   r   rf   )r(   r   rf   s      r+   r   "DanglingReferencesVisitor.__init__  s!    ((8 +F(r.   c                    g rZ   r/   r  s     r+   unknown_visit'DanglingReferencesVisitor.unknown_visit  s    r.   c                b   UR                   (       d  UR                  S5      (       d  g US   nU R                  R                  R	                  U5      nUb5  US	 X1S'   U R                  R
                  U   R                  US9  SUl         g U R                   H  nU" U5      (       d  M    g    X R                  R                  ;   a)  U R                  R                  R                  SU S3US9nOSU;   d  S	U;   aj  S
nSU;  a  US-  nOSU;  a  US-  nS	U;  a  US-  nOUR                  S	5      (       d  US-  nSU;   d  SU;   a  US-  n[        R                  " SU5      /nO/ nU R                  R                  R                  " SU S3/UQ7SU06nU R                  R                  U5      n[        R                  " UR                  UR                  US9n	 US   S   n
UR#                  U
5        UR%                  U	5        g ! [          a    U R                  R                  U	5      n
 NJf = f)Nr   r   ra   Tz>Duplicate target name, cannot be used as a unique reference: "z".rv   <>z%Did you want to embed a URI or alias?z
Opening bracket missing.z <z7
The embedded reference must be preceded by whitespace.z
Closing bracket missing.zD
The embedded reference must be the last text before the end string.z< z >z9
Whitespace around the embedded reference is not allowed.rt   zUnknown target name: "rw   r@   r   r   )rL   r   r   rd   rB   r   rh   rf   rC   rD   endswithr   r  rE   rF   rG   r   rH   rI   )r(   rM   r   r)   rk   rP   hintr   rQ   rS   rT   s              r+   visit_reference)DanglingReferencesVisitor.visit_reference  s?   ==Y 7 7y/]]""&&w/>YMMMb!444; DM!%!A!A && "B mm+++--((..&ir+6: / <C g~>g%88D( / 0Dg%88D ))#.. 7 8D7?dgo 0 1D ??2t45--((...wir:00*.0C $$S)eL	.KNE 	#  	.MM((-E	.s   H %H.-H.)r   rf   Nr0   )r4   r5   r6   r7   r8   r   r%  r,  visit_footnote_referencevisit_citation_referencer:   r/   r.   r+   r  r    s'    G
2h ;JI7r.   r  N)r8   
__future__r   __docformat__docutilsr   r   docutils.transformsr   r	   r<   rW   r   r   r   	Exceptionr   r   r   r  r  r"  r  r/   r.   r+   <module>r5     s   
 #" ! )N-y N-b>) >Bn: n:b!,i !,H%$i %$P[	 [|	) 	z9I z9zP) Pf% %8)0 )0XDJ 7 7 DJr.   