
    <i8                       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dS )z&
Transforms for resolving references.
    )annotationsreStructuredText)nodesutils)	Transformc                      e Zd ZdZdZddZdS )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  returnNonec                   | j                             t          j                  D ]}t	          |j        t          j                  s?|                    d          s*|                    d          s|                    d          rbt          |          dk    s
J d            |	                    d          }t	          |t          j
                  r1|	                    dd	          }t	          |t          j
                  1|@t	          |t          j        t          j        f          rt	          |t          j                  s$|d
                             |d
                    |d                             |d                    t          |d          si |_        t          |d          si |_        |d
         D ]}|| j         j        |<   ||j        |<   |d         D ]}||j        |<   |j                            t%          |di                      |j                            t%          |di                      t	          |j        t          j                  r6t	          |t          j                  r|j                            |           t|d
         d         |d<   g |d
<   g |d<   | j                             |           d S )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        /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/docutils/transforms/references.pyapplyzPropagateTargets.apply*   s   m++EL99 4	- 4	-F6=%*;<< NN7++/5~~h/G/G~~i00 v;;!###%M###(((55IY(<== L%//tU/KK	 Y(<== L !i%/5;K)LMM ""9el;; " e##F5M222g%%fWo6669&ABB 968	39&?@@ 746	1Um ? ?(1!"% 9?	1"55w C C<B	3D99 /66 ;R@@B B B-44 92>>@ @ @ &-66 :u}<. <. $$V,,, %UmA.F7OF5M F7OM$$V,,,,i4	- 4	-    Nr
   r   __name__
__module____qualname____doc__default_priorityr-    r.   r,   r	   r	      s:         * 5- 5- 5- 5- 5- 5-r.   r	   c                      e Zd ZdZdZddZdS )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  r
   r   c                   d | j                             t          j                  D             }d | j                             t          j                  D             }t          |          t          |          k    r| j         j                            dt          |          dt          |          d          }| j                             |          }|D ]g}t          j	        |j
        |j
        |          }| j                             |          }|                    |           |                    |           hd S t          ||          D ]\  }}|                    d          s|                    d          r0d	|_        	 |                    d          r|d         |d<   d	|_        nM|d
         s| j         j        |d                  }J|d
         d         |d<   | j                             |           	 d S )Nc                <    g | ]}|                     d           |S 	anonymousget.0nodes     r,   
<listcomp>z-AnonymousHyperlinks.apply.<locals>.<listcomp>}   s:     & & &xx$$&& & &r.   c                <    g | ]}|                     d           |S r;   r=   r?   s     r,   rB   z-AnonymousHyperlinks.apply.<locals>.<listcomp>   s:     & & &xx$$&& & &r.   zAnonymous hyperlink mismatch: z references but z+ targets.
See "backrefs" attribute for IDs.r   r   r   Tr   r   )r   r   r   	referencer   r   reportererrorset_idproblematic	rawsourceadd_backrefreplace_selfzipr   
referencedresolvedr   r(   )	r)   anonymous_refsanonymous_targetsmsgmsgidrefprbprbidr   s	            r,   r-   zAnonymousHyperlinks.apply|   s1   & &!]225?CC& & && &!]225<@@& & & ~#&7"8"888-(... ((((#.?*@*@*@*@BC CC M((--E% & &'mS]%A A A,,S11&&&  %%%%F~/@AA 	 	KC{{7## s{{8'<'<  $F>>(++ $*8$4CM#'CL!%= !!%!26'?!C #)%=#3CLM,,S111!	 	r.   Nr/   r0   r6   r.   r,   r8   r8   b   s:         , $ $ $ $ $ $r.   r8   c                  F    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
dS )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  r
   r   c                    | j         j        D ]3}|j        s|                     |           |                     |           4d S N)r   indirect_targetsrO   resolve_indirect_targetresolve_indirect_referencesr)   r   s     r,   r-   zIndirectHyperlinks.apply   sU    m4 	5 	5F? 5,,V444,,V4444	5 	5r.   c                   |                     d          }|	|d         }nY| j        j                             |          }|s8| j        j        j        D ]} ||          r n|                     |           d S | j        j        |         }|                    |           t          |t          j
                  ra|j        sZ|                    d          rEt          |d          r|                     |           d S d|_        |                     |           |`|                    d          r|d         |d<   d|v r|d= nz|                    d          r&|d         |d<   | j                            |           n?|d         r ||d<   | j                            |           n|                     |           d S ||d= d|_        d S )	Nr   r   r*   multiply_indirect   r   r   T)r>   r   nameidstransformerunknown_reference_resolversnonexistent_indirect_targetr   note_referenced_byr   r   r   rO   r   circular_indirect_referencera   r\   r(   )r)   r   r   reftarget_idresolver_function	reftargets         r,   r\   z*IndirectHyperlinks.resolve_indirect_target   s   **Y''?!'?LL=044W==L  1M= =%((00  44V<<<M%l3	$$$555y%,// 	)&	)!!),,	) v233 00888'(F$((333(X&& 	(2F8&  7Ow'' 		'0F7OM$$V,,,, ".w((000000888y!r.   c                    |d         | j         j        v r|                     |d           d S |                     |d           d S )Nr   z>which is a duplicate, and cannot be used as a unique referencezwhich does not exist)r   rc   indirect_target_errorr^   s     r,   rf   z.IndirectHyperlinks.nonexistent_indirect_target  se    ) 555&&v 0N O O O O O &&v/EFFFFFr.   c                2    |                      |d           d S )Nzforming a circular reference)rm   r^   s     r,   rh   z.IndirectHyperlinks.circular_indirect_reference  s    ""6+IJJJJJr.   c           	        d}g }|d         rd|d         d         z  }|d         D ]5}|                     | j        j                            |g                      6|d         D ]5}|                     | j        j                            |g                      6|d         r|d|d         d         z  z  }| j        j                            d|d|d	         d
|d|          }| j                            |          }t          j	        |          D ]g}	t          j        |	j        |	j        |          }
| j                            |
          }|                    |           |	                    |
           hd|_        d S )N r   z"%s" r   r   z	(id="%s")zIndirect hyperlink target z refers to target "r   z", .	base_noderD   T)r"   r   refnamesr>   refidsrF   rG   rH   r   uniqr   rI   rJ   rK   rL   rO   )r)   r   explanationnamingreflistr+   r*   rR   rS   rT   rU   rV   s               r,   rm   z(IndirectHyperlinks.indirect_target_error  s   '? 	2vgq11F7O 	A 	ADNN4=155dB??@@@@- 	= 	=BNN4=/33B;;<<<<%= 	5kF5M!$444Fm$***	***KKK9DJ + L L $$S)):g&& 	" 	"C#-e= = =CM((--EOOE"""S!!!!r.   c                   |                     d          rd}| j        j        }n|                     d          rd}d }nd S ||         }|d         D ]}| j        j                            |g           }|r|                    |           |D ]U}|j        r
|d= |||<   |r ||           d|_        t          |t          j	                  r| 
                    |           V|d         D ]}| j        j                            |g           }|r|                    |           |D ]U}|j        r
|d= |||<   |r ||           d|_        t          |t          j	                  r| 
                    |           Vd S )	Nr   r   r   r+   r   Tr   r`   )r   r   r(   rt   r>   rg   rO   r   r   r   r]   ru   )	r)   r   attnamecall_methodattvalr+   ry   rT   r*   s	            r,   r]   z.IndirectHyperlinks.resolve_indirect_references,  s   >>'"" 	G-2KK^^H%% 	GKKF7O 	: 	:Dm,00r::G 5))t)444 	: 	:< 	N%G %K$$$#c5<00 :44S999	: - 	: 	:Bm*..r266G 1))R)000 	: 	:< L%G %K$$$#c5<00 :44S999	:		: 	:r.   Nr/   )r1   r2   r3   r4   r5   r-   r\   rf   rh   rm   r]   r6   r.   r,   rX   rX      s        0 0d 5 5 5 5* * * *XG G G GK K K K   .%: %: %: %: %: %:r.   rX   c                      e Zd ZdZdZddZdS )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  r
   r   c                L   | j                             t          j                  D ]~}|                    d          rg|d         }|d         D ]V}| j         j                            |g           }|r|                    |           |D ]}|j        r
|d= ||d<   d|_        Wd S )Nr   r   r{   r   T)	r   r   r   r   r   rt   r>   rg   rO   )r)   r   r   r+   ry   rT   s         r,   r-   zExternalTargets.applyh  s    m++EL99 	, 	,F~~h'' ,)"7O 	, 	,D"m488rBBG =11t1<<<& , ,< %$	N(.H'+,	, 	,r.   Nr/   r0   r6   r.   r,   r   r   T  s:           , , , , , ,r.   r   c                  "    e Zd ZdZddZddZdS )InternalTargetsi  r
   r   c                    | j                             t          j                  D ]A}|                    d          s*|                    d          s|                     |           Bd S )Nr   r   )r   r   r   r   r   resolve_reference_idsr^   s     r,   r-   zInternalTargets.apply|  si    m++EL99 	3 	3F>>(++ 3FNN74K4K 3**6222	3 	3r.   c                   |d         D ]w}| j         j                            |          }| j         j                            |g           }|r|                    |           |D ]}|j        r
|r|d= ||d<   d|_        xdS )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   rc   r>   rt   rg   rO   )r)   r   r+   r   ry   rT   s         r,   r   z%InternalTargets.resolve_reference_ids  s    " 7O 	$ 	$DM)--d33Em,00r::G 5))t)444 $ $<  )I#(CL#$	$ 	$r.   Nr/   )r1   r2   r3   r5   r-   r   r6   r.   r,   r   r   x  sB        3 3 3 3
$ $ $ $ $ $r.   r   c                  R    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dS )	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   ♣r
   r   c                    g | _         | j        j        }|                     |          | j        _        |                     |           |                                  |                                  d S rZ   )autofootnote_labelsr   autofootnote_startnumber_footnotesnumber_footnote_referencessymbolize_footnotesresolve_footnotes_and_citations)r)   startnums     r,   r-   zFootnotes.apply  sj    #% =3+/+@+@+J+J(''111  """,,.....r.   c                L   | j         j        D ]}	 t          |          }|dz  }|| j         j        vrn$|                    dt          j        d|                     |d         D ]}| j         j                            |g           D ]}|t          j	        |          z  }|
                    d           t          |d                   t          |d                   cxk    rdk    sn J |d         d         |d<   |                    |d         d                    | j                             |           d|_        |d         sX|d	         sP|d                             |           | j                             ||           | j                            |           |S )
z
        Assign numbers to autonumbered footnotes.

        For labeled autonumbered footnotes, copy the number over to
        corresponding footnote references.
        Trb   r   rp   r   r   r   r   dupnames)r   autofootnotesstrrc   insertr   labelfootnote_refsr>   Textdelattrr   rK   r(   rO   appendnote_explicit_targetr   )r)   r   footnoter   r+   rT   s         r,   r   zFootnotes.number_footnotes  s    3 	7 	7HHA 555	
 OOAu{2u55666 ) ( (=6::4DD ( (C5:e,,,CKK	***x//3s5z??GGGGaGGGGGG#+E?1#5CL((UA777M,,S111#'CLL( G$ 7Xj-A 7!((///228XFFF(//666r.   c           	        d}| j         j        D ]}|j        s|                    d          r 	 | j        |         }n# t
          $ r t          | j                  }|dk    rdnd}| j         j                            d| d| d|	          }| j         	                    |          }| j         j        |d
         D ]}|j        s|                    d          rt          j        |j        |j        |          }	| j         	                    |	          }
|                    |
           |                    |	           Y  d
S w xY w|t          j        |          z  }| j         j        |         }| j         j        |         }||d<   | j                             |           t          |d                   dk    sJ |                    |d         d                    d|_        |dz  }d
S )z3Assign numbers to autonumbered footnote references.r   r   rb   srp   z0Too many autonumbered footnote references: only z corresponding footnotez available.rr   Nr   rD   r   T)r   autofootnote_refsrO   r   r   
IndexErrorr   rF   rG   rH   r   rI   rJ   rK   rL   r   rc   r   r(   )r)   r   irT   r   nr   rR   rS   rU   rV   r*   r   s                r,   r   z$Footnotes.number_footnote_references  s=   =2 	 	C| s{{733 03   011q55CCbm,22K"#K K<=K K K$' 3 ) ) ,,S11=:122> * *C| !s{{9'='= ! +-eE E EC M0055EOOE***$$S))))!" 5:e$$$C&u-B}(,HCLM$$S)))s5z??a''''  UA///CLFAA=	 	s   ?DEEc                   g }| j         j        D ]}t          | j         j        t	          | j                            \  }}| j        |         |dz   z  }|                    |           |                    dt          j	        d|                     | j         xj        dz  c_        | j         
                    |           d}| j         j        D ]}	 |t          j        ||                   z  }n# t          $ r | j         j                            dt	          |          z  |          }| j         
                    |          }	| j         j        |d         D ]}|j        s|                    d          rt          j        |j        |j        |	          }
| j         
                    |
          }|                    |           |                    |
           Y  dS w xY w| j         j        |         }t	          |d	                   dk    sJ |d	         d         |d<   | j                             |           |                    |d	         d                    |dz  }dS )
z<Add symbols indexes to "[*]"-style footnotes and references.rb   r   rp   zOToo many symbol footnote references: only %s corresponding footnotes available.rr   Nr   rD   r   )r   symbol_footnotesdivmodsymbol_footnote_startr   symbolsr   r   r   r   rH   symbol_footnote_refsr   r   rF   rG   rO   r   rI   rJ   rK   rL   r(   )r)   labelsr   repsindex	labeltextr   rT   rR   rS   rU   rV   s               r,   r   zFootnotes.symbolize_footnotes;  s   6 	+ 	+H !D!$T\!2!24 4KD%U+tax8IMM)$$$OOAu{2y99:::M//14//M  ****=5 	 	Cuz&),,,   m,22;=@[[I # 3 % % ,,S11==abbA * *C| !s{{7';'; ! +-eE E EC M0055EOOE***$$S)))) }5a8Hx''1,,,,#E?1-CLM$$S)))  UA///FAA/	 	s   C11C.G$#G$c                F   | j         j        D ]C}|d         D ]8}|| j         j        v r(| j         j        |         }|                     ||           9D| j         j        D ]C}|d         D ]8}|| j         j        v r(| j         j        |         }|                     ||           9DdS )za
        Link manually-labeled footnotes and citations to/from their
        references.
        r   N)r   	footnotesr   resolve_references	citationscitation_refs)r)   r   r   ry   citations        r,   r   z)Footnotes.resolve_footnotes_and_citations`  s    
 / 	? 	?H!'* ? ?DM777"m9%@G++Hg>>>? / 	? 	?H!'* ? ?DM777"m9%@G++Hg>>>?	? 	?r.   c                :   t          |d                   dk    sJ |d         d         }|D ]g}|j        r
|                    d           ||d<   t          |d                   dk    sJ |                    |d         d                    d|_        hd|_        d S )Nr   rb   r   r   r   T)r   rO   r   rK   )r)   notery   r*   rT   s        r,   r   zFootnotes.resolve_referencesp  s    4;1$$$$%[^ 	  	 C| KK	"""CLs5z??a''''SZ]+++CLLr.   r/   )r1   r2   r3   r4   r5   r   r   r-   r   r   r   r   r   r6   r.   r,   r   r     s        9 9v 9  G"/ / / /  :! ! ! !F# # # #J? ? ? ?      r.   r   c                      e Zd ZdS )#CircularSubstitutionDefinitionErrorN)r1   r2   r3   r6   r.   r,   r   r   ~  s        Dr.   r   c                      e Zd ZdZdZ	 d ZdS )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                             t          j                            }|D ]}d}|d         }||v r|}	n*|	                                }
|
                    |
d           }	|	%| j         j                            d|z  |          }nO||	         }t          |                                          |k    r"| j         j                            d|	z            }|r| j                             |          }t          j        |j        |j        |          }| j                             |          }|                    |           |                    |           7|j        }|                    |          }d	|j        v s	d
|j        v rL|dk    rFt/          ||dz
           t          j                  r#||dz
                                           ||dz
  <   d|j        v s	d
|j        v r\t          |          |dz   k    rFt/          ||dz            t          j                  r#||dz                                            ||dz   <   |                                }	 |                    t          j                  D ]v}||d         	                                         }||                    |g           v rt:          ||                             |	           ||d<   |                    |           wne# t:          $ rW |j        }t/          |t          j                  r[| j         j                            dt          j         |j        |j                  |j!        |          }|                    |           n|}|"                    d          r|d         }|"                    d          | j         j                            d|z  |          }| j                             |          }t          j        |j        |j        |          }| j                             |          }|                    |           |                    |           Y -w xY w|                    |j#                   |j#        D ]:}t/          |t          j$                  rd|v r| j         %                    |           ;d S )Nline_length_limiti'  rp   r   z(Undefined substitution referenced: "%s".rr   z;Substitution definition "%s" exceeds the line-length-limit.rD   ltrimtrimr   rb   rtrimz
ref-originz*Circular substitution definition detected:)liners   z2Circular substitution definition referenced: "%s".)&r   substitution_defssubstitution_namesr$   settingslistr   r   substitution_referencelowerr>   rF   rG   r   astextrH   rI   rJ   rK   rL   r   r   
attributesr   r   rstriplstripdeepcopy
setdefaultr   r   substitution_definitionliteral_blockr   r   childrenReferentialnote_refname)r)   defsnormednestedr   
subreflistrT   rR   r   keynormed_namesubdefrS   rU   rV   r   r   subdef_copy
nested_refnested_name
ref_originrA   s                         r,   r-   zSubstitutions.apply  sK   }.1#DM$:$7@ @ $-//0LMMNN
 R	9 R	9CC)nG$%mmoojjd33{m,22@ +. 3 0 0 cv}}''*;;;-06624789 9C  ,,S11'mS]%A A A,,S11&&&  %%%ZFLL%%E6,,,V...199F519,=,1J"8 "89(.uqy(9(@(@(B(BF519%6,,,V...KK%!)++"6%!)#4ejAA ,(.uqy(9(@(@(B(BF519% //++K!"-"5"54#6 #6 2 2J"(I)>)D)D)F)F"GK"f&7&7R&H&HHHAA;'..s333/2J|,%%j11112 7   fe&CDD *-066D+F,<,2,<> >#[F	 7 < <C
 '',,,, "%J$,,\:: >%/%=
 %,,\:: >-066 ")*5? 7 A AC !M0055E+s}EC C CC M0055EOOE***$$S)))/0 [1222 $, 9 9dE$566 9 !D((2248889[R	9 R	9s   BL55ERRNr0   r6   r.   r,   r   r     s?         4 >Z9 Z9 Z9 Z9 Z9r.   r   c                  .    e Zd ZdZdZ	 d	dZd	dZd ZdS )
TargetNotesz
    Creates a footnote for each external target in the text, and corresponding
    footnote references after each reference.
    i  r
   r   c                t    t          j        | ||           |j                            dg           | _        d S )N)	startnodeclass)r   __init__detailsr>   classes)r)   r   r   s      r,   r   zTargetNotes.__init__
  s8    4Y???? (,,Wb99r.   c                   i }g }| j                             t          j                  D ]}|                    d          s|d         }g }|D ]5}|                    | j         j                            |g                      6|s]|                     |d         ||          }|d         |vr |||d         <   |	                    |           | j                             t          j
                  D ]u}|                    d          s|                    d          rH|                     |d         |g|          }|d         |vr |||d         <   |	                    |           v| j                            |           d S )Nr   r   r<   )r   r   r   r   r   r"   rt   r>   make_target_footnoter   rE   r   rL   )	r)   notesnodelistr   r   refsr+   r   rT   s	            r,   r-   zTargetNotes.apply  s   m++EL99 	* 	*F>>(++ 7OED B BDM266tR@@AAAA 001A4168 8Hhu,,*2fX&')))=((99 	. 	.C77;'' {{8$$ .44S]SE5:< <x=--+3E#h-(OOH---##H-----r.   c                ,   ||v r2||         }t          |d                   dk    sJ |d         d         }nt          j                    }| j                            |          }d|z   }d|d<   |g|d<   t          j                    }|t          j        d||          z  }||z  }| j                            |           | j                            ||           |D ]5}t          |t          j
                  rt          j        |d          }	|	d	xx         | j        z  cc<   | j                            |	           | j                            |	           |j                            |          dz   }
|	g}t#          j        | j        j                  s_| j        r0|                    dt          j        d
| j                             n(|                    dt          j        d
                     |j                            |
|           7|S )Nr   rb   r   zTARGET_NOTE: autorp   )r   )r   r   r    )textClasses)r   r   r   r   rH   	paragraphrE   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_paragraphrT   refnoder   ry   s               r,   r   z TargetNotes.make_target_footnote-  s%   U??V}Hx())Q....$W-a0MM~''H-..x88K ,k9M HV!.HW!&!2!2%/"fV"L"L"LL**HM++H555M..xBBB 	. 	.C#u|,, .}1MMMGI$,.M//888M++G444J$$S))A-EiG4T]5KLL 7< 7NN5<S$,GGGI I I I NN1ejoo666JeW----r.   Nr/   )r1   r2   r3   r4   r5   r   r-   r   r6   r.   r,   r   r     sb         
 : : : :
. . . .<" " " " "r.   r   c                      e Zd ZdZdZddZdS )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  r
   r   c                b   t          | j        j        dg           sd S | j                            t          j                  D ]l}|j        s2| j        j                            |                    d                    r<|	                                r|
                    d           d|_        md S )N
use_bibtexr   T)r$   r   r   r   r   citation_referencerO   rc   r>   r   r   r)   rA   s     r,   r-   zCitationReferences.apply_  s    t}-|R@@ 	FM))%*BCC 		% 		%D
 }  5 9 9$((9:M:M N 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dS )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  r
   r   c                   t          | j        | j        j        j                  }| j                            |           | j                            t          j                  D ]y}|j        sp|	                    d          r|d         r|d         d         }n|d         r|d         d         }n|d         }| j        j
                            d|z  |           zd S )Nr<   r   r   r   r   z(Hyperlink target "%s" is not referenced.rr   )DanglingReferencesVisitorr   rd   re   walkr   r   r   rN   r>   rF   info)r)   visitorr   rx   s       r,   r-   zDanglingReferences.apply~  s    +MM%AC C 	7### m++EL99 	0 	0F$ 0::k** 
 '? -#G_Q/FFE] -#E]1-FF $G_F&++>(. , 0 0 0!	0 	0r.   Nr/   r0   r6   r.   r,   r  r  n  s:        
 
 0 0 0 0 0 0r.   r  c                  2    e Zd ZdZddZddZddZexZZdS )	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.
    r
   r   c                b    t           j                            | |           || _        || _        d S rZ   )r   SparseNodeVisitorr   r   re   )r)   r   re   s      r,   r   z"DanglingReferencesVisitor.__init__  s0    ((x888 +F(((r.   c                    d S rZ   r6   r  s     r,   unknown_visitz'DanglingReferencesVisitor.unknown_visit  s    r.   c                   |j         s|                    d          sd S |d         }| j        j                            |          }|7|d= ||d<   | j        j        |                             |           d|_         d S | j        D ]} ||          r d S || j        j        v r&| j        j        	                    d| d|          }nd|v sd	|v r]d
}d|vr|dz  }n	d|vr|dz  }d	|vr|dz  }n|
                    d	          s|dz  }d|v sd|v r|dz  }t          j        d|          g}ng } | j        j        j	        d| dg|R d|i}| j                            |          }t          j        |j        |j        |          }		 |d         d         }
n*# t           $ r | j                            |	          }
Y nw xY w|                    |
           |                    |	           d S )Nr   r   r`   Tz>Duplicate target name, cannot be used as a unique reference: "z".rr   <>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.rp   zUnknown target name: "rs   rD   r   r   )rO   r   r   rc   r>   r   rg   re   rF   rG   endswithr   r   rH   rI   rJ   r   rK   rL   )r)   rA   r   r*   rj   rR   hintr   rS   rU   rV   s              r,   visit_referencez)DanglingReferencesVisitor.visit_reference  s   = 	Y 7 7 	Fy/]"&&w//>YDMMb!444;;; DMF!%!A 	 	  &&  dm+++-(..+&+ + +6: / < <CC g~~>g%%88DD(( / 0Dg%%88DD ))#.. 8 7 8D7??dgoo 0 1D ?2t445.$-(.:w:::00 0 0*.0 0C $$S))eLLL	.KNEE 	. 	. 	.M((--EEE	.#s   F $GGNr/   )	r1   r2   r3   r4   r   r  r  visit_footnote_referencevisit_citation_referencer6   r.   r,   r  r    sj         G G G G
   2 2 2 2h ;JI777r.   r  N)r4   
__future__r   __docformat__docutilsr   r   docutils.transformsr   r	   r8   rX   r   r   r   	Exceptionr   r   r   r   r  r  r  r6   r.   r,   <module>r     s  
  # " " " " "" ! ! ! ! ! ! ! ! ) ) ) ) ) )N- N- N- N- N-y N- N- N-b> > > > >) > > >Bn: n: n: n: n: n: n: n:b!, !, !, !, !,i !, !, !,H%$ %$ %$ %$ %$i %$ %$ %$P[ [ [ [ [	 [ [ [|	 	 	 	 	) 	 	 	z9 z9 z9 z9 z9I z9 z9 z9zP P P P P) P P Pf% % % % % % % %8)0 )0 )0 )0 )0 )0 )0 )0XDJ DJ DJ DJ DJ 7 DJ DJ DJ DJ DJr.   