
    
3jҟ                    f   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\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)
SectionIDs   a  
Add identifiers to sections.

If the "legacy_ids" configuration setting is False, the rST parser
does not generate identifiers for implicit targets (e.g. sections)
in order to give explicit targets preferential access to identifiers
matching their reference name.

However, the `parts.Contents` transform and most writers
expect sections to have an identifier, so this transform adds them.
   c                    [        U R                  R                  SS5      (       a  g U R                  R                  [        R
                  5       H  nU R                  R                  U5        M      g )N
legacy_idsT)getattrdocumentsettingsfindallr   sectionset_idselfnodes     X/home/wildlama/miniconda3/lib/python3.13/site-packages/docutils/transforms/references.pyapplySectionIDs.apply   sM    4==))<>>MM))%--8DMM  & 9     NreturnNone__name__
__module____qualname____firstlineno____doc__default_priorityr   __static_attributes__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)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)r   r   r   target
isinstanceparentTextElementhasattrlen	next_nodesystem_message	Invisible
Targetableextendr2   r3   r0   updater   figurecaptionremove
note_refid)r   r4   r:   idnames        r   r   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,k :r   r   Nr   r   r   r   r   r(   r(   &   s    * 6-r   r(   c                  &    \ rS rSrSrSrSS jrSrg)AnonymousHyperlinksw   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,   Tr0   r   )r   r   r   	referencegetr4   r9   reportererrorr   problematic	rawsourceadd_backrefreplace_selfzipr8   
referencedresolvedr0   rC   )
r   r   anonymous_refsanonymous_targetsmsgmsgidrefprbprbidr4   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   Nr   r   r   r   r   rH   rH   w   s    , $r   rH   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_targetsrW   resolve_indirect_targetresolve_indirect_referencesr   r4   s     r   r   IndirectHyperlinks.apply   s9    mm44F??,,V4,,V4 5r   c                   UR                  S5      nUR                  S5      nU(       a&  U R                  R                  R                  U5      nOsU R                  R                  R                  U5      nU R                  R                  R                  U5      nU(       a"  U(       d  U 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                  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+   rD   multiply_indirect   r,   r0   T)rN   r   r0   r1   nameidsr   transformerunknown_reference_resolversnonexistent_indirect_targetnote_referenced_byr5   r   r4   rW   r8   circular_indirect_referencerl   rf   rC   )r   r4   r-   r+   	reftargetresolver_functions         r   rf   *IndirectHyperlinks.resolve_indirect_target   s   **Y'

7#))--e4I++//8IMM))--g6E,,Y7 ))EE "$V,,  F 008$$$.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 R                   R                  R                  US   S5      c  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   r1   rN   indirect_target_errorrh   s     r   rq   .IndirectHyperlinks.nonexistent_indirect_target$  sN    ==""6)#4b9A&&v 0N O &&v/EFr   c                (    U R                  US5        g )Nzforming a circular reference)ry   rh   s     r   rs   .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 )Nrx   r1   z"%s" r   r0   z	(id="%s")zIndirect hyperlink target z refers to target "r-   z", .	base_noderL   T)r>   r   refnamesrN   refidsrO   rP   r   r   uniqr   rQ   rR   rS   rT   rW   )r   r4   explanationnamingreflistrE   rD   rZ   r[   r\   r]   r^   s               r   ry   (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,   r1   rE   r-   Tr0   rk   )r8   r   rC   r   rN   rr   rW   r5   r   r4   rg   r   )	r   r4   attnamecall_methodattvalrE   r   r\   rD   s	            r   rg   .IndirectHyperlinks.resolve_indirect_referencesE  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   Nr   )r    r!   r"   r#   r$   r%   r   rf   rq   rs   ry   rg   r&   r   r   r   ra   ra      s1    0d 5.`GK.%:r   ra   c                  &    \ rS rSrSrSrSS jrSrg)ExternalTargetsim  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,   r1   r   r-   T)	r   r   r   r4   r8   r   rN   rr   rW   )r   r4   r,   rE   r   r\   s         r   r   ExternalTargets.apply  s    mm++ELL9F~~h'')"7OD"mm4488rBG11t1<&<<$	N(.H'+  '	 , :r   r   Nr   r   r   r   r   r   r   m  s      ,r   r   c                  ,    \ rS rSrSrSS jrSS jrSrg)InternalTargetsi  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   r4   r8   resolve_reference_idsrh   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">
r1   r   r-   r+   TN)r   rn   rN   r   rr   rW   )r   r4   rE   r+   r   r\   s         r   r   %InternalTargets.resolve_reference_ids  s    " 7ODMM))--d3Emm,,00r:G))t)4<<I#(L#  $r   r   Nr   )r    r!   r"   r#   r%   r   r   r&   r   r   r   r   r     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 rd   )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.
Trm   r   rx   r1   r-   r0   r+   dupnames)r   autofootnotesstrrn   insertr   labelfootnote_refsrN   Textdelattrr9   rS   rC   rW   appendnote_explicit_targetr   )r   r   footnoter   rE   r\   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+   rm   srx   z0Too many autonumbered footnote references: only z corresponding footnotez available.r   Nr-   rL   r0   T)r   autofootnote_refsrW   r8   r   
IndexErrorr9   rO   rP   r   r   rQ   rR   rS   rT   r   rn   r0   rC   )r   r   ir\   r   nr   rZ   r[   r]   r^   rD   r   s                r   r   $Footnotes.number_footnote_references1  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.rm   r   rx   zOToo many symbol footnote references: only %s corresponding footnotes available.r   Nr+   rL   r0   )r   symbol_footnotesdivmodsymbol_footnote_startr9   symbolsr   r   r   r   r   symbol_footnote_refsr   r   rO   rP   rW   r8   rQ   rR   rS   rT   rC   )r   labelsr   repsindex	labeltextr   r\   rZ   r[   r]   r^   s               r   r   Footnotes.symbolize_footnotesT  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.
r1   N)r   	footnotesr   resolve_references	citationscitation_refs)r   r   r   r   citations        r   r   )Footnotes.resolve_footnotes_and_citationsy  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 )Nr0   rm   r   r-   r+   T)r9   rW   r   rS   )r   noter   rD   r\   s        r   r   Footnotes.resolve_references  s    4;1$$$%[^C||KK	"Ls5z?a'''SZ]+CL  r   )r   r   )r    r!   r"   r#   r$   r%   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)r    r!   r"   r#   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'  rx   r-   z(Undefined substitution referenced: "%s".r   z;Substitution definition "%s" exceeds the line-length-limit.rL   ltrimtrimr   rm   rtrimz
ref-originz*Circular substitution definition detected:)liner   z2Circular substitution definition referenced: "%s".)&r   substitution_defssubstitution_namesr   r   listr   r   substitution_referencelowerrN   rO   rP   r9   astextr   rQ   rR   rS   rT   r6   r   
attributesr5   r   rstriplstripdeepcopy
setdefaultr   r   substitution_definitionliteral_blockr   r8   childrenReferentialnote_refname)r   defsnormednestedr   
subreflistr\   rZ   r-   keynormed_namesubdefr[   r]   r^   r6   r   subdef_copy
nested_refnested_name
ref_originr   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   Nr   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__detailsrN   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,   r1   rK   )r   r   r   r4   r8   r>   r   rN   make_target_footnoter   rM   r   rT   )	r   notesnodelistr4   r1   refsrE   r   r\   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$ )Nr1   rm   r   zTARGET_NOTE: autorx   )r,   )r-   r  r    )textClasses)r9   r   r   r   r   	paragraphrM   note_autofootnoter   r5   r4   footnote_referencer   note_autofootnote_refnote_footnote_refr6   r   r   get_trim_footnote_ref_spacer   r   inliner   )r   r,   r  r  r   footnote_namefootnote_idfootnote_paragraphr\   refnoder   r   s               r   r   TargetNotes.make_target_footnoteF  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   Nr   )
r    r!   r"   r#   r$   r%   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)CitationReferencesik  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_referencerW   rn   rN   r   r   r   s     r   r   CitationReferences.applyx  s    t}}--|R@@MM))%*B*BCD
 }} 5 5 9 9$((9:M N N{{}}Y' $ Dr   r   Nr   r   r   r   r   r  r  k  s     %r   r  c                  &    \ rS rSrSrSrSS jrSrg)DanglingReferencesi  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.
iR  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 )NrK   r1   r   r0   r+   z(Hyperlink target "%s" is not referenced.r   )DanglingReferencesVisitorr   ro   rp   walkr   r   r4   rV   rN   rO   info)r   visitorr4   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   Nr   r   r   r   r   r  r    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 rd   )r   SparseNodeVisitorr   r   rp   )r   r   rp   s      r   r   "DanglingReferencesVisitor.__init__  s!    ((8 +F(r   c                    g rd   r   r   s     r   unknown_visit'DanglingReferencesVisitor.unknown_visit  s    r   c                @   UR                   (       d  UR                  S5      (       d  g US   nU R                  R                  R	                  US5      nU(       a5  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    Uc)  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-   rx   r+   rk   Tz>Duplicate target name, cannot be used as a unique reference: "z".r   <>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.zUnknown target name: "r   rL   r0   r   )rW   r8   r   rn   rN   r0   rr   rp   rO   rP   endswithr   r  r   rQ   rR   r   rS   rT   )r   r   r-   rD   ru   rZ   hintr   r[   r]   r^   s              r   visit_reference)DanglingReferencesVisitor.visit_reference  s6   ==Y 7 7y/]]""&&w3YMMMb!444; DM "&!A!A && "B :--((..&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   
G5 5%HH)r   rp   Nr   )r    r!   r"   r#   r$   r   r+  r2  visit_footnote_referencevisit_citation_referencer&   r   r   r   r!  r!    s'    G
3j ;JI7r   r!  N)r$   
__future__r   __docformat__docutilsr   r   docutils.transformsr   r	   r(   rH   ra   r   r   r   	Exceptionr   r   r   r  r  r(  r!  r   r   r   <module>r;     s   
 #" ! )' '*N-y N-b>) >Br: r:j!,i !,H%$i %$P[	 [|	) 	z9I z9zP) Pf% %8)0 )0XEJ 7 7 EJr   