o
    N=&b	                     @   sT   d Z dZddlmZ ddlmZ G dd deZG dd deZG d	d
 d
eZdS )z
Miscellaneous transforms.
ZreStructuredText    )nodes)	Transformc                   @      e Zd ZdZdZdd ZdS )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                 C   s$   | j }|jd | |j| d S )Ncallback)	startnodedetailsparentremove)selfpending r   <usr/lib/python3.10/site-packages/docutils/transforms/misc.pyapply   s   zCallBack.applyN__name__
__module____qualname____doc__default_priorityr   r   r   r   r   r      s    
r   c                   @   r   )ClassAttributez|
    Move the "class" attribute specified in the "pending" node into the
    immediately following non-comment element.
       c                 C   s   | j }|j}|}|rDt||d t|D ]&}|| }t|tjs(t|tjr)q|d  |j	d 7  < |j
|  d S |}|j}|s
| jjjd|j	d  t|j|j|jd}|| d S )N   classesclassz,No suitable element following "%s" directive	directiveline)r   r	   rangeindexlen
isinstancer   Z	InvisibleZsystem_messager   r
   documentreportererrorZliteral_blockZ	rawsourcer   Zreplace_self)r   r   r	   childr   elementr$   r   r   r   r   ,   s0   
zClassAttribute.applyNr   r   r   r   r   r   #   s    r   c                   @   s$   e Zd ZdZdZdd Zdd ZdS )Transitionsa  
    Move transitions at the end of sections up the tree.  Complain
    on transitions after a title, 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                 C   s"   | j tjD ]}| | qd S )N)r"   findallr   
transitionvisit_transition)r   noder   r   r   r   `   s   zTransitions.applyc                 C   s  |j |}d }|dks&t|j d tjrC|dks&t|j d tjrC|dkrCt|j tjs6t|j tjs6J | jjj	d|j
|jd}nt|j |d  tjrZ| jjj	d|j
|jd}|rg|j || |d7 }|t|j k spJ |t|j d kr{d S |}|t|j d kr|j }|j d u r| jjj	d|jd}|j |j |d | d S |j |}|t|j d ks|j | |j |d | d S )	Nr   r      z4Document or section may not begin with a transition.)sourcer   zZAt least one body element must separate transitions; adjacent transitions are not allowed.z'Document may not end with a transition.r   )r	   r   r!   r   titleZsubtitler"   sectionr#   r$   r-   r   r)   insertr    r
   )r   r+   r   r$   Zsiblingr   r   r   r*   d   sR   
zTransitions.visit_transitionN)r   r   r   r   r   r   r*   r   r   r   r   r'   F   s
    r'   N)	r   Z__docformat__docutilsr   Zdocutils.transformsr   r   r   r'   r   r   r   r   <module>   s   #