o w#[@sXdZdZddlmZddlmZmZGdddeZGdddeZGd d d eZ d S) z Miscellaneous transforms. reStructuredText)nodes) TransformTransformErrorc@eZdZdZdZddZdS)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:/usr/lib/python3/dist-packages/docutils/transforms/misc.pyapplyszCallBack.applyN__name__ __module__ __qualname____doc__default_priorityrrrrrrs rc@r)ClassAttributez| Move the "class" attribute specified in the "pending" node into the immediately following non-comment element. cCs|j}|j}|}|rDt||dt|D]&}||}t|tjs(t|tjr)q|d|j d7<|j |dS|}|j}|s |j j j d|j dt|j|j|jd}||dS)Nclassesclassz,No suitable element following "%s" directive directiveline)r r rangeindexlen isinstancer Invisiblesystem_messager r documentreportererror literal_block rawsourcer replace_self)r rr childr!elementr(rrrr,s0   zClassAttribute.applyNrrrrrr#s rc@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&traverser transitionvisit_transition)r noderrrr`s zTransitions.applycCs|j|}d}|dks&t|jdtjrC|dks&t|jdtjrC|dkrCt|jtjs6t|jtjs6J|jjj d|j |j d}nt|j|dtj rZ|jjj d|j |j d}|rg|j |||d7}|t|jkspJ|t|jdkr{dS|}|t|jdkr|j}|jdur|jjj d|j d}|j |j|d|dS|j|}|t|jdks|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 r!r#rtitlesubtitler&sectionr'r(r4rr0insertr"r )r r2r!r(siblingrrrr1dsR     zTransitions.visit_transitionN)rrrrrrr1rrrrr.Fs  r.N) r __docformat__docutilsrdocutils.transformsrrrrr.rrrrs #