U C^@sXdZdZddlmZddlmZmZGdddeZGdddeZGd d d eZ d S) z Miscellaneous transforms. ZreStructuredText)nodes) TransformTransformErrorc@seZdZdZdZddZdS)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. icCs$|j}|jd||j|dS)Ncallback) startnodedetailsparentremove)selfpendingr >/tmp/pip-install-6_kvzl1k/docutils/docutils/transforms/misc.pyapplyszCallBack.applyN__name__ __module__ __qualname____doc__default_priorityrr r r rrs rc@seZdZdZdZddZdS)ClassAttributez| Move the "class" attribute specified in the "pending" node into the immediately following non-comment element. cCs|j}|j}|}|rt||dt|D]L}||}t|tjs,t|tjrRq,|d|j d7<|j |dS|}|j}q|j j j d|j dt|j|j|jd}||dS)Nclassesclassz,No suitable element following "%s" directive directiveline)rr rangeindexlen isinstancerZ InvisibleZsystem_messagerr documentreportererrorZ literal_blockZ rawsourcerZ replace_self)r r r childrelementr$r r rr,s.   zClassAttribute.applyNrr r r rr#src@s$eZdZdZdZddZddZdS) 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::
...
... into this::
...
... i>cCs"|jtjD]}||qdS)N)r"Ztraverser transitionvisit_transition)r noder r rr`szTransitions.applycCs|j|}d}|dksLt|jdtjr|dksLt|jdtjr|dkrt|jtjslt|jtjslt|jj j d|j |j d}n.t|j|dtj r|jj j d|j |j d}|r|j|||d7}|t|jkst|t|jdkrdS|}|t|jdkr`|j}|jdkrR|jj j d|j d}|j|j|d|dS|j|}q|j||j|d|dS) Nrrz4Document or section may not begin with a transition.)sourcerzZAt least one body element must separate transitions; adjacent transitions are not allowed.z'Document may not end with a transition.r)r rr!rtitleZsubtitler"sectionAssertionErrorr#r$r,rr(insertr r )r r*rr$Zsiblingr r rr)dsX    zTransitions.visit_transitionN)rrrrrrr)r r r rr'Fsr'N) rZ __docformat__ZdocutilsrZdocutils.transformsrrrrr'r r r rs  #