
    Fe
                        d Z ddlmZ ddlmZmZmZ ddlmZ ddl	m
Z
 ddlmZ erddlmZ ddlmZ  G d	 d
ej"                        Z G d de      ZddZy)z:Docutils transforms used by Sphinx when reading documents.    )annotations)TYPE_CHECKINGAnycast)nodes)addnodes)SphinxTransform)Node)Sphinxc                  0    e Zd ZdZddZddZd	dZddZy)
RefOnlyListCheckerzRaise `nodes.NodeFound` if non-simple list item is encountered.

    Here 'simple' means a list item containing only a paragraph with a
    single reference in it.
    c                "    t         j                  N)r   	NodeFoundselfnodes     G/usr/lib/python3/dist-packages/sphinx/transforms/compact_bullet_list.pydefault_visitz RefOnlyListChecker.default_visit   s    oo    c                     y r    r   s     r   visit_bullet_listz$RefOnlyListChecker.visit_bullet_list   s    r   c                   g }|j                   D ].  }t        |t        j                        r|j	                  |       0 t        |      dk7  rt        j                  t        |d   t        j                        st        j                  |d   }t        |      dk7  rt        j                  t        |d   t        j                        st        j                  t        j                  )N   r   )children
isinstancer   	Invisibleappendlenr   	paragraphr   pending_xrefSkipChildren)r   r   r   childparas        r   visit_list_itemz"RefOnlyListChecker.visit_list_item   s    !]] 	'EeU__5&	' x=A//!(1+u7//!{t9>//!$q'8#8#89//!   r   c                     y)z"Invisible nodes should be ignored.Nr   r   s     r   invisible_visitz"RefOnlyListChecker.invisible_visit/   s    r   N)r   r
   returnNone)r   znodes.bullet_listr)   r*   )r   znodes.list_itemr)   r*   )__name__
__module____qualname____doc__r   r   r&   r(   r   r   r   r   r      s    ! r   r   c                      e Zd ZdZdZddZy)RefOnlyBulletListTransformzChange refonly bullet lists to use compact_paragraphs.

    Specifically implemented for 'Indices and Tables' section, which looks
    odd when html_compact_lists is false.
    d   c                     j                   j                  ry d fd} j                  j                  t        j
                        D ]  } ||      s|j                  t        j                        D ]g  }t        t        j                  |d         }t        t        j                  |d         }t        j                         }||z  }|j                  ||       i  y )Nc                    t        j                        }	 | j                  |       y# t        j                  $ r Y yw xY w)z*Check for list with only references in it.TF)r   documentwalkr   r   )r   visitorr   s     r   check_refonly_listz<RefOnlyBulletListTransform.apply.<locals>.check_refonly_list@   s?    (7G		'"  ?? s   * A A r   )r   r
   r)   bool)confightml_compact_listsr4   findallr   bullet_list	list_itemr   r!   	referencer   compact_paragraphreplace)r   kwargsr7   r   itemr%   refcompact_paras   `       r   applyz RefOnlyBulletListTransform.apply<   s    ;;))	 MM))%*;*;< 	5D!$' LL9 5Da9DuQ8C#+#=#=#?L C'LLL|45	5r   N)rA   r   r)   r*   )r+   r,   r-   r.   default_priorityrE   r   r   r   r0   r0   4   s    
 5r   r0   c                8    | j                  t               ddddS )NbuiltinT)versionparallel_read_safeparallel_write_safe)add_transformr0   )apps    r   setuprN   T   s&    01 "# r   N)rM   r   r)   zdict[str, Any])r.   
__future__r   typingr   r   r   docutilsr   sphinxr   sphinx.transformsr	   docutils.nodesr
   sphinx.applicationr   GenericNodeVisitorr   r0   rN   r   r   r   <module>rW      sH    @ " + +   -#)11 D5 5@r   