
    k7i                    t    S r SSKJr  SrSSKrSSKJrJrJr   " S S\5      r	 " S S	5      r
 " S
 S\5      rg)a  
This package contains modules for standard tree transforms available
to Docutils components. Tree transforms serve a variety of purposes:

- To tie up certain syntax-specific "loose ends" that remain after the
  initial parsing of the input plaintext. These transforms are used to
  supplement a limited syntax.

- To automate the internal linking of the document tree (hyperlink
  references, footnote references, etc.).

- To extract useful information from the document tree. These
  transforms may be used to construct (for example) indexes and tables
  of contents.

Each transform is an optional step that a Docutils component may
choose to perform on the parsed document.
    )annotationsreStructuredTextN)	languagesApplicationErrorTransformSpecc                      \ rS rSrSrg)TransformError!    N)__name__
__module____qualname____firstlineno____static_attributes__r       V/home/james-whalen/.local/lib/python3.13/site-packages/docutils/transforms/__init__.pyr	   r	   !   s    r   r	   c                  2    \ rS rSrSrSr SSS jjrS rSrg)		Transform%   z1Docutils transform component abstract base class.Nc                    Xl          X l         [        R                  " UR                  R
                  UR                  5      U l        g)z1
Initial setup for in-place document transforms.
N)document	startnoder   get_languagesettingslanguage_codereporterlanguage)selfr   r   s      r   __init__Transform.__init__+   sE    
 !-"	 "..++X->->@5r   c                    [        S5      e)z5Override to apply the transform to the document tree.z"subclass must override this method)NotImplementedError)r   kwargss     r   applyTransform.apply<   s    !"FGGr   )r   r   r   NreturnNone)	r   r   r   r   __doc__default_priorityr   r$   r   r   r   r   r   r   %   s    ;I6"Hr   r   c                  f    \ rS rSrSrSS jrSSS jjrSS jrSSS jjrSS jr	SS	 jr
SS
 jrSrg)TransformerA   aG  
Store "transforms" and apply them to the document tree.

Collect lists of `Transform` instances from Docutils
components (`TransformSpec` instances).
Apply collected "transforms" to the document tree.

Also keeps track of components by component type name.

https://docutils.sourceforge.io/docs/peps/pep-0258.html#transformer
c                p    / U l          / U l         Xl         / U l         SU l         0 U l         SU l        g )NFr   )
transformsunknown_reference_resolversr   appliedsorted
componentsserialno)r   r   s     r   r   Transformer.__init__N   sU    	 ,.(	
 !J32	
 	r   Nc                    Uc  UR                   nU R                  U5      nU R                  R                  XASU45        SU l        g)a  
Store a single transform.  Use `priority` to override the default.
`kwargs` is a dictionary whose contents are passed as keyword
arguments to the `apply` method of the transform.  This can be used to
pass application-specific data to the transform instance.
NF)r+   get_priority_stringr0   appendr3   )r   transform_classpriorityr#   priority_strings        r   add_transformTransformer.add_transformm   sH     &77H228<tV<	>r   c                    U H<  nU R                  UR                  5      nU R                  R                  X2S0 45        M>     SU l        g)z3Store multiple transforms, with default priorities.NF)r8   r+   r0   r9   r3   )r   transform_listr:   r<   s       r   add_transformsTransformer.add_transforms{   sJ    -O"66002OOO"" 4<>  .
 r   c                    UR                   nUc  UR                  nU R                  U5      nU R                  R	                  XCU0 45        SU l        g)z4Store a transform with an associated `pending` node.NF)	transformr+   r8   r0   r9   r3   )r   pendingr;   r:   r<   s        r   add_pendingTransformer.add_pending   sQ    !++&77H228<w;	=r   c                L    U =R                   S-  sl         SXR                   4-  $ )z|
Return a string, `priority` combined with `self.serialno`.

This ensures FIFO order on transforms with identical priority.
   z	%03d-%03d)r5   )r   r;   s     r   r8   Transformer.get_priority_string   s$     	h666r   c                   / nU Hl  n[        U[        5      (       d  M  U R                  UR                  5       5        X0R                  UR
                  '   UR                  UR                  5        Mn     SU l        S nUR                  US9  U =R                  U-  sl        U R                  (       a  [        R                  " S[        SS9  gg)a?  
Store each component's default transforms and reference resolvers.

Transforms are stored with default priorities for later sorting.
"Unknown reference resolvers" are sorted and stored.
Components that don't inherit from `TransformSpec` are ignored.

Also, store components by type name in a mapping for later lookup.
Fc                    U R                   $ r&   )r;   )fs    r   keyfun4Transformer.populate_from_components.<locals>.keyfun   s    ::r   )keyztThe `unknown_reference_resolvers` hook chain will be removed in Docutils 1.0.
Use a transform to resolve references.   )
stacklevelN)
isinstancer   rA   get_transformsr4   component_typeextendr1   r3   sortwarningswarnDeprecationWarning)r   r4   	resolvers	componentrN   s        r   populate_from_components$Transformer.populate_from_components   s     	#Ii77	 8 8 :;8AOOI445YBBC $ 	6"((I5(++MM C -< ,r   c                L   U R                   R                  R                  U R                   R                  5        U R                  (       a  U R
                  (       d   U R                  R                  SS9  SU l        U R                  R                  5       u  pp4U" U R                   US9nUR                  " S0 UD6  U R                  R                  XX445        U R                  (       a  M  U R                   R                  R                  U R                   R                  5        g)z6Apply all of the stored transforms, in priority order.T)reverse)r   Nr   )r   r   attach_observernote_transform_messager0   r3   rW   popr$   r2   r9   detach_observer)r   r;   r:   rE   r#   rD   s         r   apply_transformsTransformer.apply_transforms   s    ..MM00	2oo;; $$T$2"9=9L9L9N6Hw'IIOO%f%LLG LM ooo 	..MM00	2r   )r2   r4   r   r5   r3   r0   r1   r'   r&   )r(   str)r   r   r   r   r*   r   r=   rA   rF   r8   r]   re   r   r   r   r   r-   r-   A   s*    
>7<<2r   r-   )r*   
__future__r   __docformat__rX   docutilsr   r   r   r	   r   r-   r   r   r   <module>rk      sD   
& #"  ? ?	% 	H H8C2- C2r   