o
    ^ib                     @   s   d dl mZmZ er&ddlmZ ddlmZmZmZ ddl	m
Z
 ddlmZ g dZdZd	Zd
ddee dddefddZdddee dddefddZdddedefddZdddedefddZd'd!d"Zd'd#d$Zd'd%d&Zd S )(    )TYPE_CHECKINGMatch   )BlockParser)BaseRenderer
BlockStateInlineState)InlineParser)Markdown)mathmath_in_quotemath_in_listz7^ {0,3}\$\$[ \t]*\n(?P<math_text>[\s\S]+?)\n\$\$[ \t]*$z"\$(?!\s)(?P<math_text>.+?)(?!\s)\$blockr   mstater   returnc                 C   s&   | d}|d|d | d S )N	math_text
block_mathtyperaw   groupappend_tokenend)r   r   r   text r   O/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/mistune/plugins/math.pyparse_block_math   s   
r   inliner	   r   c                 C   s"   | d}|d|d | S )Nr   inline_mathr   r   )r    r   r   r   r   r   r   parse_inline_math   s   
r"   rendererr   r   c                 C      d| d S )Nz<div class="math">$$
z

$$</div>
r   r#   r   r   r   r   render_block_math      r&   c                 C   r$   )Nz<span class="math">\(z	\)</span>r   r%   r   r   r   render_inline_math   r'   r(   mdr
   Nc                 C   sb   | j jdttdd | jjdttdd | jr-| jjdkr/| jdt	 | jdt
 dS dS dS )a'  A mistune plugin to support math. The syntax is used
    by many markdown extensions:

    .. code-block:: text

        Block math is surrounded by $$:

        $$
        f(a)=f(b)
        $$

        Inline math is surrounded by `$`, such as $f(a)=f(b)$

    :param md: Markdown instance
    r   listbeforer!   linkhtmlN)r   registerBLOCK_MATH_PATTERNr   r    INLINE_MATH_PATTERNr"   r#   NAMEr&   r(   r)   r   r   r   r   #   s   r   c                 C      | j j| j jddd dS )z(Enable block math plugin in block quote.r   r*   r+   N)r   insert_ruleblock_quote_rulesr3   r   r   r   r   :      r   c                 C   r4   )z!Enable block math plugin in list.r   r*   r+   N)r   r5   
list_rulesr3   r   r   r   r   ?   r7   r   )r)   r
   r   N)typingr   r   block_parserr   corer   r   r   inline_parserr	   markdownr
   __all__r0   r1   strintr   r"   r&   r(   r   r   r   r   r   r   r   <module>   s     

