
    Ki8                    P   d Z ddlmZ dZddlmZmZ ddlmZ  G d de      Z	 G d d	e      Z
 G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d dej*                        Zy)z&
Transforms for resolving references.
    )annotationsreStructuredText)nodesutils)	Transformc                      e Zd ZdZdZddZy)PropagateTargetsa  
    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                n   | j                   j                  t        j                        D ]  }t	        |j
                  t        j                        s3|j                  d      s"|j                  d      s|j                  d      r\t        |      dk(  sJ d       |j                  d      }t	        |t        j                        r.|j                  dd	      }t	        |t        j                        r.|Dt	        |t        j                  t        j                  f      rt	        |t        j                        s|d
   j                  |d
          |d   j                  |d          t        |d      si |_        t        |d      si |_        |d
   D ]*  }|| j                   j                   |<   ||j                  |<   , |d   D ]  }||j                  |<    |j                  j#                  t%        |di              |j                  j#                  t%        |di              t	        |j
                  t        j&                        r7t	        |t        j(                        r|j
                  j+                  |       Y|d
   d   |d<   g |d
<   g |d<   | j                   j-                  |        y )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        j/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docutils/transforms/references.pyapplyzPropagateTargets.apply*   s^   mm++ELL9 4	-F6==%*;*;<NN7+v~~h/G~~i0v;!#M%MM#(((5IY(<(<=%//tU/K	 Y(<(<= !i%//5;K;K)LM"9ell;e##F5M2g%%fWo69&AB68	39&?@46	1Um ?(1!!"% 9?	11"5? w C<B	33D9C //66 ;R@B--44 92>@ &--6:u}}<.$$V, %UmA.F7OF5M F7OMM$$V,i4	-    NreturnNone__name__
__module____qualname____doc__default_priorityr+    r,   r*   r	   r	      s    * 5-r,   r	   c                      e Zd ZdZdZddZy)AnonymousHyperlinksa  
    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                F   | j                   j                  t        j                        D cg c]  }|j	                  d      r| }}| j                   j                  t        j
                        D cg c]  }|j	                  d      r| }}t        |      t        |      k7  r| j                   j                  j                  dt        |      dt        |      d      }| j                   j                  |      }|D ]k  }t        j                  |j                  |j                  |      }| j                   j                  |      }|j                  |       |j                  |       m y t        ||      D ]  \  }}	|j                  d      s|j                  d      r)d|	_        	 |	j                  d      r|	d   |d<   d|_        R|	d	   s| j                   j$                  |	d      }	D|	d	   d
   |d<   | j                   j'                  |        y c c}w c c}w )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+   zAnonymousHyperlinks.apply|   s   !]]225??C&xx$ & & "]]225<<@&xx$ & & ~#&7"88--((.. (#.?*@BCC MM((-E% &''mmS]]%A,,S1&  %& ~/@A 	KC{{7#s{{8'< $F>>(+$*8$4CM#'CL!%=!%!2!26'?!C #)%=#3CLMM,,S1!	'&&s   H3HNr-   r0   r6   r,   r*   r8   r8   b   s    , $r,   r8   c                  D    e Zd ZdZdZd
dZd
dZd
dZd
dZd
dZ	d
dZ
y	)IndirectHyperlinksab  
    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                    | j                   j                  D ]0  }|j                  s| j                  |       | j	                  |       2 y N)r   indirect_targetsrG   resolve_indirect_targetresolve_indirect_referencesr'   r   s     r*   r+   zIndirectHyperlinks.apply   s>    mm44 	5F??,,V4,,V4	5r,   c                n   |j                  d      }||d   }nh| j                  j                  j                  |      }|sA| j                  j                  j                  D ]  } ||      s y  | j                  |       y | j                  j                  |   }|j                  |       t        |t        j                        rU|j                  sI|j                  d      r8t        |d      r| j                  |       y d|_        | j                  |       |`|j                  d      r|d   |d<   d|v rq|d= nm|j                  d      r$|d   |d<   | j                  j!                  |       n8|d   r!||d<   | j                  j!                  |       n| j                  |       y ||d= d|_        y )	Nr   r   r(   multiply_indirect   r   r   T)r=   r   nameidstransformerunknown_reference_resolversnonexistent_indirect_targetr   note_referenced_byr   r   r   rG   r   circular_indirect_referencerZ   rU   r&   )r'   r   r   reftarget_idresolver_function	reftargets         r*   rU   z*IndirectHyperlinks.resolve_indirect_target   s   **Y'?!'?L==0044W=L 11MM=%(0 =
 44V<MM%%l3	$$$5y%,,/&&!!),v23008'(F$((3(X&(2F8& 7Ow''0F7OMM$$V,".w((0008y!r,   c                    |d   | j                   j                  v r| j                  |d       y | j                  |d       y )Nr   z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)r   r\   indirect_target_errorrW   s     r*   r_   z.IndirectHyperlinks.nonexistent_indirect_target  sC    ) 5 55&&v 0N O &&v/EFr,   c                (    | j                  |d       y )Nzforming a circular reference)rf   rW   s     r*   ra   z.IndirectHyperlinks.circular_indirect_reference  s    ""6+IJr,   c           	         d}g }|d   rd|d   d   z  }|d   D ]7  }|j                  | j                  j                  j                  |g              9 |d   D ]7  }|j                  | j                  j                  j                  |g              9 |d   r|d|d   d   z  z  }| j                  j
                  j                  d|d|d	   d
|d|      }| j                  j                  |      }t        j                  |      D ]k  }	t        j                  |	j                  |	j                  |      }
| j                  j                  |
      }|j                  |       |	j                  |
       m d|_        y )N r   z"%s" r   r   z	(id="%s")zIndirect hyperlink target z refers to target "r   z", .	base_noder;   T)r    r   refnamesr=   refidsr>   r?   r@   r   uniqr   rA   rB   rC   rD   rG   )r'   r   explanationnamingreflistr)   r(   rK   rL   rM   rN   rO   s               r*   rf   z(IndirectHyperlinks.indirect_target_error  sk   '?vgq11F7O 	ADNN4==1155dB?@	A- 	=BNN4==//33B;<	=%=kF5M!$444Fmm$$**	*K9DJ + L $$S)::g& 	"C##--e=CMM((-EOOE"S!	" r,   c                   |j                  d      rd}| j                  j                  }n|j                  d      rd}d }ny ||   }|d   D ]  }| j                  j                  j	                  |g       }|r|j                  |       |D ]T  }|j                  r|d= |||<   |r ||       d|_        t        |t        j                        sD| j                  |       V  |d   D ]  }| j                  j                  j	                  |g       }|r|j                  |       |D ]T  }|j                  r|d= |||<   |r ||       d|_        t        |t        j                        sD| j                  |       V  y )	Nr   r   r   r)   r   Tr   rY   )r   r   r&   rm   r=   r`   rG   r   r   r   rV   rn   )	r'   r   attnamecall_methodattvalr)   rr   rM   r(   s	            r*   rV   z.IndirectHyperlinks.resolve_indirect_references,  sz   >>'"G--22K^^H%GK7O 	:Dmm,,00r:G))t)4 	:<<	N%G$#c5<<044S9	:		: - 	:Bmm**..r26G))R)0 	:<<L%G$#c5<<044S9	:		:r,   Nr-   )r1   r2   r3   r4   r5   r+   rU   r_   ra   rf   rV   r6   r,   r*   rQ   rQ      s1    0d 5*XGK.%:r,   rQ   c                      e Zd ZdZdZddZy)ExternalTargetsa  
    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                \   | j                   j                  t        j                        D ]  }|j	                  d      s|d   }|d   D ]_  }| j                   j
                  j                  |g       }|r|j                  |       |D ]  }|j                  r|d= ||d<   d|_          a  y )Nr   r   rt   r   T)	r   r   r   r   r   rm   r=   r`   rG   )r'   r   r   r)   rr   rM   s         r*   r+   zExternalTargets.applyh  s    mm++ELL9 	,F~~h')"7O 	,D"mm4488rBG11t1<& ,<<$	N(.H'+,		,	,r,   Nr-   r0   r6   r,   r*   ry   ry   T  s      ,r,   ry   c                       e Zd ZdZddZddZy)InternalTargetsi  c                    | j                   j                  t        j                        D ]7  }|j	                  d      r|j	                  d      r'| j                  |       9 y )Nr   r   )r   r   r   r   r   resolve_reference_idsrW   s     r*   r+   zInternalTargets.apply|  sI    mm++ELL9 	3F>>(+FNN74K**62	3r,   c                    |d   D ]  }| j                   j                  j                  |      }| j                   j                  j                  |g       }|r|j	                  |       |D ]   }|j
                  r|r|d= ||d<   d|_        "  y)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   rt   r   r   TN)r   r\   r=   rm   r`   rG   )r'   r   r)   r   rr   rM   s         r*   r~   z%InternalTargets.resolve_reference_ids  s    " 7O 	$DMM))--d3Emm,,00r:G))t)4 $<<I#(CL#$	$r,   Nr-   )r1   r2   r3   r5   r+   r~   r6   r,   r*   r|   r|   x  s    3
$r,   r|   c                  P    e Zd ZdZdZdZ	 g dZddZd ZddZ	ddZ
dd	Zdd
Zy)	Footnotesa  
    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                    g | _         | j                  j                  }| j                  |      | j                  _        | j	                  |       | j                          | j                          y rS   )autofootnote_labelsr   autofootnote_startnumber_footnotesnumber_footnote_referencessymbolize_footnotesresolve_footnotes_and_citations)r'   startnums     r*   r+   zFootnotes.apply  sV    #% ==33+/+@+@+J(''1  ",,.r,   c                (   | j                   j                  D ]w  }	 t        |      }|dz  }|| j                   j                  vrn*|j	                  dt        j                  d|             |d   D ]  }| j                   j                  j                  |g       D ]  }|t        j                  |      z  }|j                  d       t        |d         t        |d         cxk(  rdk(  sJ  J |d   d   |d<   |j                  |d   d          | j                   j                  |       d|_          |d   r&|d	   r-|d   j                  |       | j                   j!                  ||       | j"                  j                  |       z |S )
z
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        Tr[   r   ri   r   r   r   r   dupnames)r   autofootnotesstrr\   insertr   labelfootnote_refsr=   Textdelattrr   rC   r&   rG   appendnote_explicit_targetr   )r'   r   footnoter   r)   rM   s         r*   r   zFootnotes.number_footnotes  s~    33 	7HHA 5 55	 
 OOAu{{2u56 ) (==66::4D (C5::e,,CKK	*x/3s5z?GaGGGGG#+E?1#5CL((UA7MM,,S1#'CL(( G$Xj-A!((/228XF((//6'	7( r,   c           	        d}| j                   j                  D ]  }|j                  s|j                  d      r!	 | j                  |   }|t        j                  |      z  }| j                   j                   |   }| j                   j"                  |   }||d<   | j                   j%                  |       t        |d         dk(  sJ |j                  |d   d          d|_        |dz  } y
# t
        $ r t        | j                        }|dkD  rdnd}| j                   j                  j                  d| d| d|	      }| j                   j                  |      }| j                   j                  |d
 D ]  }|j                  s|j                  d      r!t        j                  |j                  |j                  |      }	| j                   j                  |	      }
|j                  |
       |j                  |	        Y  y
w xY w)z3Assign numbers to autonumbered footnote references.r   r   r[   sri   z0Too many autonumbered footnote references: only z corresponding footnotez available.rk   Nr   r;   r   T)r   autofootnote_refsrG   r   r   
IndexErrorr   r>   r?   r@   r   rA   rB   rC   rD   r   r\   r   r&   )r'   r   irM   r   nr   rK   rL   rN   rO   r(   r   s                r*   r   z$Footnotes.number_footnote_references  s   ==22 	C||s{{73003$ 5::e$$C&&u-B}}((,HCLMM$$S)s5z?a'''  UA/CLFA=	
  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                
   g }| j                   j                  D ]  }t        | j                   j                  t	        | j
                              \  }}| j
                  |   |dz   z  }|j                  |       |j                  dt        j                  d|             | j                   xj                  dz  c_        | j                   j                  |        d}| j                   j                  D ]  }	 |t        j                  ||         z  }| j                   j                  |   }t	        |d	         dk(  sJ |d	   d   |d<   | j                   j-                  |       |j)                  |d	   d          |dz  } y# t        $ r | j                   j                  j                  dt	        |      z  |      }| j                   j                  |      }	| j                   j                  |d D ]  }|j                   s|j#                  d      r!t        j$                  |j&                  |j&                  |	      }
| j                   j                  |
      }|j)                  |       |j+                  |
        Y  yw xY w)
z<Add symbols indexes to "[*]"-style footnotes and references.r[   r   ri   zOToo many symbol footnote references: only %s corresponding footnotes available.rk   Nr   r;   r   )r   symbol_footnotesdivmodsymbol_footnote_startr   symbolsr   r   r   r   r@   symbol_footnote_refsr   r   r>   r?   rG   r   rA   rB   rC   rD   r&   )r'   labelsr   repsindex	labeltextr   rM   rK   rL   rN   rO   s               r*   r   zFootnotes.symbolize_footnotes;  s8   66 	+H !D!D!$T\\!24KD%U+tax8IMM)$OOAu{{2y9:MM//14/MM  *	+ ==55 	Cuzz&),,  }}55a8Hx'1,,,#E?1-CLMM$$S)  UA/FA/	  mm,,22;=@[I # 3 % ,,S1====abA *C||s{{7'; ++--eEC MM005EOOE*$$S)* s   6FC<JJc                   | j                   j                  D ]P  }|d   D ]F  }|| j                   j                  v s| j                   j                  |   }| j                  ||       H R | j                   j                  D ]P  }|d   D ]F  }|| j                   j
                  v s| j                   j
                  |   }| j                  ||       H R y)za
        Link manually-labeled footnotes and citations to/from their
        references.
        r   N)r   	footnotesr   resolve_references	citationscitation_refs)r'   r   r   rr   citations        r*   r   z)Footnotes.resolve_footnotes_and_citations`  s    
 // 	?H!'* ?DMM777"mm99%@G++Hg>?	?
 // 	?H!'* ?DMM777"mm99%@G++Hg>?	?r,   c                    t        |d         dk(  sJ |d   d   }|D ]V  }|j                  r|j                  d       ||d<   t        |d         dk(  sJ |j                  |d   d          d|_        X d|_        y )Nr   r[   r   r   r   T)r   rG   r   rC   )r'   noterr   r(   rM   s        r*   r   zFootnotes.resolve_referencesp  s    4;1$$$%[^ 	 C||KK	"CLs5z?a'''SZ]+CL	  r,   r-   )r1   r2   r3   r4   r5   r   r   r+   r   r   r   r   r   r6   r,   r*   r   r     s@    9v 9G"/:!F#J? r,   r   c                      e Zd Zy)#CircularSubstitutionDefinitionErrorN)r1   r2   r3   r6   r,   r*   r   r   ~  s    r,   r   c                      e Zd ZdZdZ	 d Zy)SubstitutionsaF  
    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           	      
   | j                   j                  }| j                   j                  }i }t        | j                   j                  dd      }t        | j                   j                  t        j                              }|D ]  }d}|d   }||v r|}	n"|j                         }
|j                  |
d       }	|	+| j                   j                  j                  d|z  |      }nI||	   }t        |j                               |kD  r(| j                   j                  j                  d|	z        }|r| j                   j                  |      }t        j                   |j"                  |j"                  |      }| j                   j                  |      }|j%                  |       |j'                  |       2|j(                  }|j+                  |      }d	j,                  v sd
|j,                  v rA|dkD  r<t/        ||dz
     t        j0                        r||dz
     j3                         ||dz
  <   d|j,                  v sd
|j,                  v rMt        |      |dz   kD  r<t/        ||dz      t        j0                        r||dz      j5                         ||dz   <   |j7                         }	 |j                  t        j                        D ]\  }||d   j                            }||j9                  |g       v rt:        ||   j=                  |	       ||d<   |j=                  |       ^ 	 |j'                  |jF                         |jF                  D ]=  }t/        |t        jH                        sd|v s#| j                   jK                  |       ?  y # t:        $ ro |j(                  }t/        |t        j>                        rm| j                   j                  j                  dt        j@                  |j"                  |j"                        |jB                  |      }|j'                  |       n|}|jE                  d      r|d   }|jE                  d      r| j                   j                  j                  d|z  |      }| j                   j                  |      }t        j                   |j"                  |j"                  |      }| j                   j                  |      }|j%                  |       |j'                  |       Y w xY w)Nline_length_limiti'  ri   r   z(Undefined substitution referenced: "%s".rk   z;Substitution definition "%s" exceeds the line-length-limit.r;   ltrimtrimr   r[   rtrimz
ref-originz*Circular substitution definition detected:)linerl   z2Circular substitution definition referenced: "%s".)&r   substitution_defssubstitution_namesr"   settingslistr   r   substitution_referencelowerr=   r>   r?   r   astextr@   rA   rB   rC   rD   r   r   
attributesr   r   rstriplstripdeepcopy
setdefaultr   r   substitution_definitionliteral_blockr   r   childrenReferentialnote_refname)r'   defsnormednestedr   
subreflistrM   rK   r   keynormed_namesubdefrL   rN   rO   r   r   subdef_copy
nested_refnested_name
ref_originrH   s                         r*   r+   zSubstitutions.apply  s   }}..11#DMM$:$:$7@ $--//0L0LMN
 R	9CC)nG$%mmojjd3{mm,,22@ +. 3 0 cv}}'*;;--006624789C ,,S1''mmS]]%A,,S1&  %ZZFLL%E6,,,V...19F519,=,1JJ"8(.uqy(9(@(@(BF519%6,,,V...K%!)+"6%!)#4ejjA(.uqy(9(@(@(BF519% //+K!"-"5"544#6 2J"(I)>)D)D)F"GK"f&7&7R&HHAA;'..s3/2J|,%%j12@ [112 $,, 9dE$5$56 !D(22489[R	9d 7 fe&C&C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   *A>NCTB.TTNr0   r6   r,   r*   r   r     s    4 >Z9r,   r   c                  ,    e Zd ZdZdZ	 ddZddZd Zy)TargetNotesz
    Creates a footnote for each external target in the text, and corresponding
    footnote references after each reference.
    i  c                v    t        j                  | ||       |j                  j                  dg       | _        y )N)	startnodeclass)r   __init__detailsr=   classes)r'   r   r   s      r*   r   zTargetNotes.__init__
  s.    4Y? ((,,Wb9r,   c                   i }g }| j                   j                  t        j                        D ]  }|j	                  d      s|d   }g }|D ]7  }|j                  | j                   j                  j                  |g              9 |s[| j                  |d   ||      }|d   |vsy|||d   <   |j                  |        | j                   j                  t        j                        D ]^  }|j                  d      s|j	                  d      s'| j                  |d   |g|      }|d   |vsF|||d   <   |j                  |       ` | j                  j                  |       y )Nr   r   r:   )r   r   r   r   r   r    rm   r=   make_target_footnoter   r<   r   rD   )	r'   notesnodelistr   r   refsr)   r   rM   s	            r*   r+   zTargetNotes.apply  s_   mm++ELL9 	*F>>(+7OED BDMM2266tR@AB001A4168Hhu,*2fX&')	*  ==((9 	.C77;'{{8$44S]SE5:<x=-+3E#h-(OOH-	. 	##H-r,   c                F   ||v r!||   }t        |d         dk(  sJ |d   d   }nt        j                         }| j                  j	                  |      }d|z   }d|d<   |g|d<   t        j
                         }|t        j                  d||      z  }||z  }| j                  j                  |       | j                  j                  ||       |D ]K  }t        |t        j                        rt        j                  |d      }	|	d	xx   | j                  z  cc<   | j                  j                  |	       | j                  j                  |	       |j                  j!                  |      dz   }
|	g}t#        j$                  | j                  j&                        sc| j                  r2|j)                  dt        j*                  d
| j                               n%|j)                  dt        j,                  d
             |j                  j)                  |
|       N |S )Nr   r[   r   zTARGET_NOTE: autori   )r   )r   r   r    )textClasses)r   r   r   r   r@   	paragraphr<   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_paragraphrM   refnoder   rr   s               r*   r   z TargetNotes.make_target_footnote-  s   U?V}Hx()Q...$W-a0M~~'H--..x8K ,k9M HV!.HW!&!2%//"fV"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<<NN5<<S$,,GI NN1ejjo6JJeW-	.  r,   Nr-   )r1   r2   r3   r4   r5   r   r+   r   r6   r,   r*   r   r     s#    
 :
.<"r,   r   c                      e Zd ZdZdZddZy)CitationReferenceszResolve <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                x   t        | j                  j                  dg       sy | j                  j                  t        j
                        D ]l  }|j                  s4| j                  j                  j                  |j                  d            rD|j                         sU|j                  d       d|_        n y )N
use_bibtexr   T)r"   r   r   r   r   citation_referencerG   r\   r=   r   r   r'   rH   s     r*   r+   zCitationReferences.apply_  s    t}}--|R@MM))%*B*BC 		%D
 }} 5 5 9 9$((9:M N{{}Y' $		%r,   Nr-   r0   r6   r,   r*   r   r   R  s     %r,   r   c                      e Zd ZdZdZddZy)DanglingReferencesu  
    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                   t        | j                  | j                  j                  j                        }| j                  j	                  |       | j                  j                  t        j                        D ]l  }|j                  r|j                  d      r"|d   r	|d   d   }n|d   r	|d   d   }n|d   }| j                  j                  j                  d|z  |       n y )Nr:   r   r   r   r   z(Hyperlink target "%s" is not referenced.rk   )DanglingReferencesVisitorr   r]   r^   walkr   r   r   rF   r=   r>   info)r'   visitorr   rq   s       r*   r+   zDanglingReferences.apply~  s    +MMMM%%AAC 	7# mm++ELL9 	0F$$::k*
 '?#G_Q/FE]#E]1-F $G_F&&++>(. , 0!	0r,   Nr-   r0   r6   r,   r*   r   r   n  s    
 0r,   r   c                  0    e Zd ZdZddZddZddZexZZy)r   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                `    t         j                  j                  | |       || _        || _        y rS   )r   SparseNodeVisitorr   r   r^   )r'   r   r^   s      r*   r   z"DanglingReferencesVisitor.__init__  s'    ((x8 +F(r,   c                     y rS   r6   r   s     r*   unknown_visitz'DanglingReferencesVisitor.unknown_visit  s    r,   c                $   |j                   s|j                  d      sy |d   }| j                  j                  j	                  |      }|9|d= ||d<   | j                  j
                  |   j                  |       d|_         y | j                  D ]  } ||      s y  || j                  j                  v r,| j                  j                  j                  d| d|      }nd|v sd	|v rZd
}d|vr|dz  }n	d|vr|dz  }d	|vr|dz  }n|j                  d	      s|dz  }d|v sd|v r|dz  }t        j                  d|      g}ng } | j                  j                  j                  d| dg|d|i}| j                  j                  |      }t        j                  |j                  |j                  |      }		 |d   d   }
|j#                  |
       |j%                  |	       y # t         $ r | j                  j                  |	      }
Y Iw xY w)Nr   r   rY   Tz>Duplicate target name, cannot be used as a unique reference: "z".rk   <>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.ri   zUnknown target name: "rl   r;   r   r   )rG   r   r   r\   r=   r   r`   r^   r>   r?   endswithr   r   r@   rA   rB   r   rC   rD   )r'   rH   r   r(   rc   rK   hintr   rL   rN   rO   s              r*   visit_referencez)DanglingReferencesVisitor.visit_reference  s@   ==Y 7y/]]""&&w/>YDMMMb!444; DM!%!A!A 	 &	 dmm+++--((..&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   =G( ($HHNr-   )	r1   r2   r3   r4   r   r  r  visit_footnote_referencevisit_citation_referencer6   r,   r*   r   r     s'    G
2h ;JI7r,   r   N)r4   
__future__r   __docformat__docutilsr   r   docutils.transformsr   r	   r8   rQ   ry   r|   r   	Exceptionr   r   r   r   r   r  r   r6   r,   r*   <module>r     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,   