
    Ki                    r    d Z ddlmZ dZddlmZ ddlmZ  G d de      Z G d d	e      Z	 G d
 de      Z
y)z
Miscellaneous transforms.
    )annotationsreStructuredText)nodes)	Transformc                      e Zd ZdZdZddZy)CallBacka  
    Inserts a callback into a document.  The callback is called when the
    transform is applied, which is determined by its priority.

    For use with `nodes.pending` elements.  Requires a ``details['callback']``
    entry, a bound method or function which takes one parameter: the pending
    node.  Other data can be stored in the ``details`` attribute or in the
    object hosting the callback method.
    i  c                |    | j                   } |j                  d   |       |j                  j                  |       y )Ncallback)	startnodedetailsparentremove)selfpendings     d/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/docutils/transforms/misc.pyapplyzCallBack.apply   s0    ..#
#G,g&    NreturnNone__name__
__module____qualname____doc__default_priorityr    r   r   r   r      s     'r   r   c                      e Zd ZdZdZddZy)ClassAttributezg
    Move the "class" attribute specified in the "pending" node into the
    next visible element.
       c                   | j                   }|j                  dddd      D ]c  }t        |t        j                  t        j
                  f      r.|dxx   |j                  d   z  cc<   |j                  j                  |        y  | j                  j                  j                  d|j                  d   z  t        j                  |j                  |j                        |j                        }|j                  |       y )	NFT)include_selfdescendsiblingsascendclassesclassz,No suitable element following "%s" directive	directive)line)r   findall
isinstancer   	Invisiblesystem_messager   r   r   documentreportererrorliteral_block	rawsourcer)   replace_self)r   r   elementr0   s       r   r   zClassAttribute.apply.   s    ..E504T ' C 	G'EOOU5I5I#JKI'//'"::NN!!'*	 &&,,:ook*+ 1 173D3DE	 - 
 	U#r   Nr   r   r   r   r   r   r   %   s    
 $r   r   c                  $    e Zd ZdZdZddZddZy)Transitionsa  
    Move transitions at the end of sections up the tree.  Complain
    on transitions after a title, subtitle, meta, or decoration element,
    at the beginning or end of the document, and after another transition.

    For example, transform this::

        <section>
            ...
            <transition>
        <section>
            ...

    into this::

        <section>
            ...
        <transition>
        <section>
            ...
    i>  c                    | j                   j                  t        j                        D ]  }| j	                  |        y )N)r.   r*   r   
transitionvisit_transition)r   nodes     r   r   zTransitions.applyZ   s4    MM))%*:*:; 	(D!!$'	(r   c                   |j                   j                  |      }|j                         }d}t        |j                   t        j
                  t        j                  f      sd}nl|dk(  sHt        |t        j                  t        j                  t        j                  t        j                  f      rd}nt        |t        j                        rd}|r| j
                  j                  j                  ||      }t	        j                         |j                   |<   	 |j                   j                  d       ||j                   |<   |j                   j!                  |d	z   |       |d	z  }t        |j                   t        j
                  t        j                  f      sy |t%        |j                         k  sJ |t%        |j                         d	z
  k7  ry |}|t%        |j                         d	z
  k(  r|j                   }|j                   C| j
                  j                  j                  d
|      }|j                   j'                  |       y |j                   j                  |      }|t%        |j                         d	z
  k(  r|j                   j)                  |       |j                   j!                  |d	z   |       y # t        j"                  $ r ||j                   |<   Y zw xY w)N z4Transition must be child of <document> or <section>.r   z4Document or section may not begin with a transition.zZAt least one body element must separate transitions; adjacent transitions are not allowed.)	base_nodeF)	recursive   z'Document may not end with a transition.)r   indexprevious_siblingr+   r   r.   sectiontitlesubtitlemeta
decorationr8   r/   warning	paragraphvalidateinsertValidationErrorlenappendr   )r   r:   r@   rA   msgrG   siblings          r   r9   zTransitions.visit_transition^   sX   !!$'002$++'FGHCaZ:&69>9>9>9I9I9K L IC(%*:*:;;Cmm,,44SD4IG!&!2DKK$$u$5 &*E"""57G4
$++'FGs4;;''''C$q((s7>>*Q..nnG~~% --0088G(, 9 . ""7+NN((1E s7>>*Q.. 	4 eai.; (( *%)E"*s   K   "K&%K&Nr   )r   r   r   r   r   r   r9   r   r   r   r6   r6   @   s    , (1/r   r6   N)r   
__future__r   __docformat__docutilsr   docutils.transformsr   r   r   r6   r   r   r   <module>rT      s@   
 #"  )'y '($Y $6O/) O/r   