o
    ,b                  
   @   s   d Z ddlmZmZ zddlmZ W n ey% Z zee ddZ[ww zddlm	Z	 W n ey>   G dd dZ	Y nw d	d
 Z
G dd deZdS )aj  
A parser for CommonMark Markdown text using `recommonmark`__.

__ https://pypi.org/project/recommonmark/

.. important:: This module is provisional

   * The "recommonmark" package is unmaintained and deprecated.
     This wrapper module will be removed in a future Docutils version.

   * The API is not settled and may change with any minor Docutils version.
    )nodes	Component)CommonMarkParserz.
Parsing "recommonmark" Markdown flavour requires the package https://pypi.org/project/recommonmark which in turn depends on https://pypi.org/project/sphinx.N)addnodesc                   @   s   e Zd ZejZdS )r   N)__name__
__module____qualname__r   pendingpending_xref r   r   Iusr/lib/python3.10/site-packages/docutils/parsers/recommonmark_wrapper.pyr   *   s    
r   c                 C   s   t | tjtjfS N)
isinstancer   literalliteral_block)noder   r   r   
is_literal/   s   r   c                   @   s>   e Zd ZdZdZ	 dZdZdd Zdd Zd	d
 Z	dd Z
dS )ParserzMarkDown parser based on recommonmark.

    This parser is provisional:
    the API is not settled and may change with any minor Docutils version.
    )ZrecommonmarkZ
commonmarkZmarkdownZmdzrecommonmark parser)parsersc                 C   s
   t | S r   )r   get_transforms)selfr   r   r   r   ?   s   
zParser.get_transformsc              
   C   s  t |dD ]\}}t||jjkr%|jd|d  }||  dS qz	t	| || W n% t
yT } z|jjr=||jd| }|| W Y d}~nd}~ww |tjD ]C}|j}d}|d t|k rt|| tjrt||d  tjrt|| ||d  ||< ||| _n|d7 }|d t|k sjq[|tD ]}d|d vr|d d q|tjD ]}d	|jv r|d |d	  |d	= q|jjs|tjD ]}|jd
}	|j||	 q|tjD ]}|jd }
d|
vrt|
 |
d< |j||
 qdS )z9Use the upstream parser and clean up afterwards.
        
z&Line %d exceeds the line-length-limit.   Nz2Parsing with "recommonmark" returned the error:
%sr   codeclasseslanguagezRaw content disabled.name)	enumeratesplitlensettingsZline_length_limitZreportererrorappendr   parse	Exception	tracebackfindallr   ZTextElementchildrenr   Textpopparentr   r   Z
attributesZraw_enabledrawwarningreplacer   r
   Zfully_normalize_nameZastext)r   ZinputstringZdocumentiliner!   errr   r'   r,   	referencer   r   r   r#   B   sh   

 	


zParser.parsec                 C   s   dS )zyDummy function to prevent spurious warnings.

        cf. https://github.com/readthedocs/recommonmark/issues/177
        Nr   )r   r   r   r   r   visit_document~   s   zParser.visit_documentc                 C   s   | j t|j d S r   )Zcurrent_noder"   r   r(   r   )r   Zmdnoder   r   r   
visit_text   s   zParser.visit_textN)r   r   r   __doc__Z	supportedZconfig_sectionZconfig_section_dependenciesr   r#   r2   r3   r   r   r   r   r   3   s    <	r   )r4   docutilsr   r   Zrecommonmark.parserr   ImportErrorr0   Zsphinxr   r   r   r   r   r   r   <module>   s   