U
    Sh                     @  s  d dl mZ d dlmZ d dl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rd dlmZ d d	lmZ d d
lmZmZ dddddZdddddZdddddZdZdZdd eD Zedd eD ZdddddZd d!d!ddd"d#d$Zd+d%d&d'd(d)d*Z dS ),    )annotations)suppressN)TYPE_CHECKINGCallableSequence)
MarkdownIt)
StateBlock)is_code_block)RendererProtocol)Token)EnvTypeOptionsDictstrztuple[list[str], str])paramsreturnc                 C  sL   t d}|| }|r@|d  d}dd |D |d fS tddS )	z8Check for multiple tags when the title is double quoted.z+^\s*(?P<tokens>[^"]+)\s+"(?P<title>.*)"\S*$tokens c                 S  s   g | ]}|  qS  )lower).0tagr   r   N/root/rtd-docs/venv/lib/python3.8/site-packages/mdit_py_plugins/admon/index.py
<listcomp>   s     z&_get_multiple_tags.<locals>.<listcomp>titlezNo match found for parametersN)recompilematchstripsplit
ValueError)r   Zre_tagsr   tagsr   r   r   _get_multiple_tags   s    

r!   )_paramsr   c              
   C  s~   |   }|sdgdfS tt t|W  5 Q R  S Q R X |d^}}d|}d}|sd| }n|dkrp|}| g|fS )z0Separate the tag name from the admonition title. r   z"")r   r   r   r!   r   joinr   r   )r"   r   r   _titleZjoinedr   r   r   r   _get_tag   s    



r&   boolc                 C  s    |   ddd pd}t|S )z7Validate the presence of the tag name after the marker.r      r#   )r   r   r'   )r   r   r   r   r   	_validate2   s    r*      )z!!!z???z???+c                 C  s   h | ]}|d  qS )r   r   r   _mr   r   r   	<setcomp>:   s     r.   c                 c  s   | ]}t |V  qd S N)lenr,   r   r   r   	<genexpr>;   s     r1   z	list[str])markupr   c                 C  s$   |  dr | drdgS dgS g S )z:Return the list of additional classes based on the markup.?+zis-collapsible collapsible-openz!is-collapsible collapsible-closed)
startswithendswith)r2   r   r   r   _extra_classes>   s
    

r7   r   int)state	startLineendLinesilentr   c                 C  s  t | |rdS | j| | j|  }| j| }| j| tkr>dS d}t}|dkr||| }| j|| }	|	tkrr|	}q|d8 }qFdS | j|| }
t|
sdS |rdS | j	}| j
}| j}|}||k r| j| dkr|d7 }qd| _	tt| }|  j|| | 7  _d}|}|d7 }||krq| j| | j|  }| j| }| j| | jk }|r\|r\q|}||k r| j| | jk rqq|| _
t|
\}}|d }| dd	d}|	|_d|_d
dd|t|	i|_d|i|_||_|
|_||g|_|rh|	 d| }| ddd}||_d
di|_||d g|_| ddd}||_||d g|_g |_| ddd}| jj| |d | | dd	d}|	|_d|_|| _	|| _
|| _|| _dS )NFr#   r   r(   Tr   
admonitionadmonition_opendivclassr   admonition_title_openpzadmonition-titleinlineadmonition_title_closer)   admonition_close)r=   )r	   ZbMarksZtShiftZeMarkssrcMARKER_CHARSMAX_MARKER_LENMARKERSr*   Z
parentTypeZlineMaxZ	blkIndent
MARKER_LENr0   ZsCountr&   pushr2   blockr$   r7   attrsmetacontentinfomapchildrenmdtokenizeline)r9   r:   r;   r<   startmaximummarkerZ
marker_lenZ
marker_posr2   r   Z
old_parentZold_line_maxZ
old_indentZ	blk_startZmarker_alignment_correctionZ	was_empty	next_lineposZis_emptyr    r   r   tokenZtitle_markupr   r   r   r=   G   s    








r=   r   zNone | Callable[..., str]None)rS   renderr   c              
   C  st   ddddddddd	}|p|}|  d
| |  d| |  d| |  d| | jjddtdddddgi dS )a  Plugin to use
    `python-markdown style admonitions
    <https://python-markdown.github.io/extensions/admonition>`_.

    .. code-block:: md

        !!! note
            *content*

    `And mkdocs-style collapsible blocks
    <https://squidfunk.github.io/mkdocs-material/reference/admonitions/#collapsible-blocks>`_.

    .. code-block:: md

        ???+ note
            *content*

    Note, this is ported from
    `markdown-it-admon
    <https://github.com/commenthol/markdown-it-admon>`_.
    r
   zSequence[Token]r8   r   r   r   )selfr   idx_optionsenvr   c                 S  s   |  ||||S r/   )ZrenderToken)r^   r   r_   r`   ra   r   r   r   renderDefault   s    z#admon_plugin.<locals>.renderDefaultr>   rE   rA   rD   Zfencer=   ZaltZ	paragraph	referenceZ
blockquotelistN)Zadd_render_rulerL   Zrulerbeforer=   )rS   r]   rb   r   r   r   admon_plugin   s    	rf   )N)!
__future__r   
contextlibr   r   typingr   r   r   Zmarkdown_itr   Zmarkdown_it.rules_blockr   Zmdit_py_plugins.utilsr	   Zmarkdown_it.rendererr
   Zmarkdown_it.tokenr   Zmarkdown_it.utilsr   r   r!   r&   r*   rJ   rI   rG   maxrH   r7   r=   rf   r   r   r   r   <module>   s(   
	r