B 0`@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 s/private/var/folders/sf/wxz_36012wxg_prv29r6623x5vlqx8/T/pip-target-tft40_m7/lib/python/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}|}xz|rxpt||dt|D]J}||}t|tjs0t|tjrVq0|d|j d7<|j |dSW|}|j}qW|j j j d|j dt|j|j|jd}||dS)Nclassesclassz,No suitable element following "%s" directive directive)line)rr rangeindexlen isinstancerZ InvisibleZsystem_messagerr documentreportererrorZ literal_blockZ rawsourcerZ replace_self)r r r childrelementr"r r rr,s(      zClassAttribute.applyN)rrrrrrr 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&x |jtjD]}||qWdS)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|}xh|t|jdkrb|j}|jdkrT|jj j d|j d}|j|j|d|dS|j|}qW|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 rrrtitleZsubtitler sectionAssertionErrorr!r"r*rr&insertrr )r r(rr"Zsiblingr r rr'dsD    zTransitions.visit_transitionN)rrrrrrr'r r r rr%Fsr%N) rZ __docformat__ZdocutilsrZdocutils.transformsrrrrr%r r r rs  #