
    hb                         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Zdddee   dddefdZdddedefdZdddedefdZddZddZddZy)    )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                 r    |j                  d      }|j                  d|d       |j                         dz   S )N	math_text
block_mathtyperaw   groupappend_tokenend)r   r   r   texts       S/var/www/html/aiagenthome/venv/lib/python3.12/site-packages/mistune/plugins/math.pyparse_block_mathr       s3    77;D	T:;557Q;    inliner
   r	   c                 l    |j                  d      }|j                  d|d       |j                         S )Nr   inline_mathr   r   )r"   r   r   r   s       r   parse_inline_mathr%      s.    77;D	d;<557Nr!   rendererr   r   c                     d|z   dz   S )Nz<div class="math">$$
z

$$</div>
 r&   r   s     r   render_block_mathr*      s    #d*^;;r!   c                     d|z   dz   S )Nz<span class="math">\(z	\)</span>r(   r)   s     r   render_inline_mathr,      s    #d*\99r!   Nc                 n   | j                   j                  dt        t        d       | j                  j                  dt
        t        d       | j                  r[| j                  j                  dk(  rA| j                  j                  dt               | j                  j                  dt               yyy)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,   mds    r   r   r   #   s      HHl$68HQWXII}&9;LU[\	{{r{{''61
\+<=
],>? 2{r!   c                 h    | j                   j                  | j                   j                  dd       y)z(Enable block math plugin in block quote.r   r.   r/   N)r   insert_ruleblock_quote_rulesr7   s    r   r   r   :   s%    HH33\&Qr!   c                 h    | j                   j                  | j                   j                  dd       y)z!Enable block math plugin in list.r   r.   r/   N)r   r:   
list_rulesr7   s    r   r   r   ?   s%    HH,,l6Jr!   )r8   r   r   N)typingr   r   block_parserr   corer   r   r	   inline_parserr
   markdownr   __all__r4   r5   strintr    r%   r*   r,   r   r   r   r(   r!   r   <module>rF      s    '*<<,#
3O ; M eCj  RU n s M VY < <c <c <: :s :s :@.R
Kr!   