
    $g9                     L   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmc mZ ddlmZ ddlZd	Zd
ZdZdZdZdZd Z ej        d          d/d            Z ej        d          d/d            Z ej        d          d/d            Zd0dZd1dZd Z ej        d          d2d            Z ej        d          d2d             Z ej        d!          d2d"            Z 	 d3d$Z!	 d4d&Z"d' Z# G d( d)e          Z$ G d* d+e          Z% G d, d-e          Z&d. Z'dS )5a  
Arithmatex.

pymdownx.arithmatex
Extension that preserves the following for MathJax use:

```
$Equation$, \(Equation\)

$$
  Display Equations
$$

\[
  Display Equations
\]

\begin{align}
  Display Equations
\end{align}
```

and `$Inline MathJax Equations$`

Inline and display equations are converted to scripts tags. You can optionally generate previews.

MIT license.

Copyright (c) 2014 - 2017 Isaac Muse <isaacmuse@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions
of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
    )	Extension)InlineProcessor)BlockProcessor)util)partialN   zN(?:(?<!\\)((?:\\{2})+)(?=\$)|(?<!\\)(\$)(?!\s)((?:\\.|[^\\$])+?)(?<!\s)(?:\$))zA(?:(?<!\\)((?:\\{2})+)(?=\$)|(?<!\\)(\$)((?:\\.|[^\\$])+?)(?:\$))zJ(?:(?<!\\)((?:\\{2})+?)(?=\\\()|(?<!\\)(\\\()((?:\\[^)]|[^\\])+?)(?:\\\)))z8(?P<dollar>[$]{2})(?P<math>((?:\\.|[^\\])+?))(?P=dollar)zH(?P<math2>\\begin\{(?P<env>[a-z]+\*?)\}(?:\\.|[^\\])+?\\end\{(?P=env)\})z&\\\[(?P<math3>(?:\\[^\]]|[^\\])+?)\\\]c                     |                      dd          } |                      dd          } |                      dd          } |                      dd          } | S )	zBasic html escaping.&z&amp;<z&lt;>z&gt;"z&quot;)replace)txts    S/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/arithmatex.py_escaper   ?   sU     ++c7
#
#C
++c6
"
"C
++c6
"
"C
++c8
$
$CJ    zThe inline MathJax Preview formatter has been deprecated in favor of the configurable 'arithmatex_fenced_format'. Please see relevant documentation for more information on how to switch before this function is removed in the future.math
arithmatexc                 $    t          | d          S )z#Inline math formatter with preview.Tpreview_inline_mathjax_formatr   language
class_namemds       r   inline_mathjax_preview_formatr   J   s     "$5555r   zThe inline MathJax formatter has been deprecated in favor of the configurable 'arithmatex_fenced_format'. Please see relevant documentation for more information on how to switch before this function is removed in the future.c                 $    t          | d          S )Inline math formatter.Fr   r   r   s       r   inline_mathjax_formatr!   U   s     "$6666r   zThe inline generic math formatter has been deprecated in favor of the configurable 'arithmatex_inline_format'. Please see relevant documentation for more information on how to switch before this function is removed in the future.c                 "    t          | |||fi |S )Inline generic formatter.)_inline_generic_format)r   r   r   r   kwargss        r   inline_generic_formatr&   `   s      "$*bKKFKKKr   spanFc                     t          j        |ddi          }|r1t          j        |dddi          }t          j        |           |_        t          j        |dddi          }t          j        |           |_        |S )r    classr   r'   MathJax_Previewscripttypezmath/tex)etreeElement
SubElementmd_utilAtomicStringtext)	r   r   r   r   tagr   elprer+   s	            r   r   r   k   s~     
sWl3	4	4B .r6G5F+GHH'--b(VZ,@AAF&t,,FKIr   \({}\)c                     t          j        |d|i          }t          j        |                    |                     |_        |S )r#   r)   )r-   r.   r0   r1   formatr2   )r   r   r   r   wrapr3   r4   s          r   r$   r$   w   s=     
sWj1	2	2B"4;;t#4#455BGIr   c                      |                      dd          }|                      dd          }|                      dd          }|dk    rt          t          |          S |dk    rt          t          |	          S d
S )>Specify which type of formatter you want and the wrapping tag.modegenericr3   r'   r   Fr3   mathjaxr   N)getr   r$   r   r%   r<   r3   r   s       r   arithmatex_inline_formatrB      s     ::fi((D
**UF
#
#CjjE**Gy-37777			-w???? 
	r   zThe fenced MathJax preview formatter has been deprecated in favor of the configurable 'arithmatex_fenced_format'. Please see relevant documentation for more information on how to switch before this function is removed in the future.c                 $    t          | d          S )z%Block MathJax formatter with preview.Tr   _fence_mathjax_formatr   r   r   optionsr   r%   s         r   fence_mathjax_preview_formatrH      s     !t4444r   c                 $    t          | d          S )zBlock MathJax formatter.Fr   rD   rF   s         r   fence_mathjax_formatrJ      s     !u5555r   zThe generic math formatter has been deprecated in favor of the configurable 'arithmatex_fenced_format'. Please see relevant documentation for more information on how to switch before this function is removed in the future.c                 $    t          | ||||fi |S )Generic block formatter.)_fence_generic_formatrF   s         r   fence_generic_formatrN      s"     !xWbSSFSSSr   divc                 f    d| d}|r|dt          |           z   dz   z  }|d| z   dz   z  }|dz  }|S )zBlock math formatter.r   z class="arithmatex">
z<div class="MathJax_Preview">
z
</div>
z'<script type="math/tex; mode=display">
z
</script>
z</div>)r   )	r   r   r   rG   r   r   r3   r%   r2   s	            r   rE   rE      so    
 +s***D 
-DMM	
 	2		D
 	HDKr   \[
{}
\]c           
      |   |d         }|d         }	|d         }
|                     d|           |	rd|	 dnd}	d                    d	                    |                    }|
r4d	d	                    d
 |
                                D                       z   nd}
d| |	 | |
 d|                    |            d| d
S )rL   classesid_valueattrsr   z id="r    z class="{}" c              3   ,   K   | ]\  }}| d | dV  dS )z="r   N ).0kvs      r   	<genexpr>z(_fence_generic_format.<locals>.<genexpr>   s2      BBDAqa<<1<<<BBBBBBr   r   r   z</)insertr8   joinitems)r   r   r   rG   r   r9   r3   r%   rS   rT   rU   s              r   rM   rM      s    
 YGj!H7OENN1j!!!&.6"x""""BH""388G#4#455GFKSC#((BBEKKMMBBBBBBBQSEJsJHJgJuJJt{{4/@/@JJCJJJJr   c                      |                      dd          }|                      dd          }|                      dd          }|dk    rt          t          |          S |dk    rt          t          ||	          S d
S )r;   r<   r=   r3   rO   r   Fr>   r?   r3   r   N)r@   r   rM   rE   rA   s       r   arithmatex_fenced_formatrc      s     ::fi((D
**UE
"
"CjjE**Gy,#6666			,#wGGGG 
	r   c                   r    e Zd ZdZd                    ej         ed          ej                  Z	d Z
d ZdS )InlineArithmatexPatternz"Arithmatex inline pattern handler.z{}{}{}\c                    |                     dd          | _        |                     dddg          }|d                             dd                              d	d          d
z   |d                             dd                              d	d          z   | _        |                     dd          | _        |                     dd          | _        t          j        | |           dS )Initialize.r=   Ftex_inline_wrap\(\)r   {}}}{}r   
inline_tagr'   r   TN)r@   r=   r   r9   rp   r   r   __init__)selfpatternconfigr9   s       r   rq   z InlineArithmatexPattern.__init__   s     zz)U33zz+eU^<<GOOC&&..sD99D@47??SVX\C]C]CeCefikoCpCpp 		 !**\6:: zz)T22 w/////r   c                 l   |                                 }|d         }|st          |          dk    r|d         }|rD|                    d| j                  |                    d          |                    d          fS |d         }|st          |          dk    r|d         }| j        rEt          || j        | j	                  |                    d          |                    d          fS t          || j	        | j                  |                    d          |                    d          fS )zSHandle notations and switch them to something that will be more detectable in HTML.r      z\\      )r9   r3   rb   )groupslenr   ESCAPED_BSLASHstartendr=   r$   r9   rp   r   r   )rr   mdatary   escapesr   s         r   handleMatchz#InlineArithmatexPattern.handleMatch   s*    ) 	 3v;;??QiG 	V??64+>??QUUSTXXUU ay 	Fa!9D< 	q)$TYDOTTTVWV]V]^_V`V`bcbgbghibjbjjj)$DOT\ZZZ\]\c\cde\f\fhihmhmnohphpppr   N)__name__
__module____qualname____doc__r8   r0   STXordETXr{   rq   r   rY   r   r   re   re      s^        ,,__W[##d))W[IIN0 0 0q q q q qr   re   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )BlockArithmatexProcessorz4MathJax block processor to find $$MathJax$$ content.c                    |                     dd          | _        |                     dddg          }|d                             dd                              d	d          d
z   |d                             dd                              d	d          z   | _        |                     dd          | _        |                     dd          | _        d| _        t          j        |          | _	        t          j        | |j                   dS )rh   r=   Ftex_block_wrap\[\]r   rl   rm   rn   ro   r   	block_tagrO   r   N)r@   r=   r   r9   r   r   matchrecompilers   r   rq   parser)rr   rs   rt   r   r9   s        r   rq   z!BlockArithmatexProcessor.__init__  s     zz)U33zz*UEN;;GOOC&&..sD99D@47??SVX\C]C]CeCefikoCpCpp 		  K77 zz)U33
z'**bi00000r   c                 d    | j         | j                             |          nd| _        | j        duS )z=Return 'True' for future Python Markdown block compatibility.N)rs   r   )rr   parentblocks      r   testzBlockArithmatexProcessor.test$  s5     37,2JT\''...PT
z%%r   c                    |}t          j        || j        ddi          }| j        r1t          j        |dddi          }t	          j        |          |_        t          j        |dddi          }t	          j        |          |_        dS )	zDefault MathJax output.r)   r   rO   r*   r+   r,   zmath/tex; mode=displayN)r-   r/   r   r   r0   r1   r2   )rr   r   r   grandparentr   r4   s         r   mathjax_outputz'BlockArithmatexProcessor.mathjax_output*  s     !+t~?VWW< 	6&vuw@Q6RSSG"/55GLfh9Q0RSS&t,,r   c                     t          j        || j        ddi          }t          j        | j                            |                    |_        dS )zGeneric output.r)   r   N)r-   r/   r   r0   r1   r9   r8   r2   )rr   r   r   r4   s       r   generic_outputz'BlockArithmatexProcessor.generic_output5  sE     fdnw6MNN&ty'7'7'='=>>r   c                 V   |                     d           | j                                        }|                    dd          }|s|                    dd          }|s|                    dd          }| j        r|                     ||           n|                     ||           dS )zFind and handle block content.r   r   rV   math2math3T)popr   	groupdictr@   r=   r   r   )rr   r   blocksry   r   s        r   runzBlockArithmatexProcessor.run;  s     	

1%%''zz&"%% 	+::gr**D 	+::gr**D< 	.-------tr   N)	r   r   r   r   rq   r   r   r   r   rY   r   r   r   r     se        >>1 1 1&& & &	- 	- 	-? ? ?    r   r   c                   (     e Zd ZdZ fdZd Z xZS )ArithmatexExtensionz(Adds delete extension to Markdown class.c           
          ddgdgddgdgddgg d	d
gddgdgddgddgddgddgd	| _          t                      j        |i | dS )rh   rj   rk   zPWrap inline content with the provided text ['open', 'close'] - Default: ['', '']r   r   zOWrap blick content with the provided text ['open', 'close'] - Default: ['', '']Tz-Use Arithmatex's smart dollars - Default TruedollarsquarebeginzEnable block syntax: "dollar" ($$...$$), "square" (\[...\]), and "begin" (\begin{env}...\end{env}). - Default: ["dollar", "square", "begin"]r   roundz\Enable block syntax: "dollar" ($$...$$), "bracket" (\(...\))  - Default: ["dollar", "round"]FzEOutput in a generic format for non MathJax libraries - Default: Falsez.Insert a preview for scripts. - Default: FalserO   z#Specify wrapper tag - Default 'div'r'   z$Specify wrapper tag - Default 'span')	ri   r   smart_dollarblock_syntaxinline_syntaxr=   r   r   rp   N)rt   superrq   )rr   argsr%   	__class__s      r   rq   zArithmatexExtension.__init__R  s    
 b 
 a "#RS---` 7#2
 fg@  !FG!#IJ5
 
: 	$)&)))))r   c                    |                     |            t          j        |dg           |                                 }t	          |                    dddg                    }|                    dd          }g }d|v r#|                    |rt          nt                     d|v r|                    t                     |rBt          dd                    |          z  |          }|j                            |d	d
           t	          |                    dg d                    }g }d|v r|                    t                     d|v r|                    t                     d|v r|                    t                      |rJt#          dd                    |          z  ||          }	|j        j                            |	dd           dS dS )z.Extend the inline and block processor objects.$r   r   r   r   Tz(?:%s)|zarithmatex-inlineg̼g@r   r   r   r   z(?s)^(?:%s)[ ]*$zarithmatex-blockgS@N)registerExtensionr   escape_chars
getConfigssetr@   appendRE_SMART_DOLLAR_INLINERE_DOLLAR_INLINERE_BRACKET_INLINEre   r_   inlinePatternsregisterRE_DOLLAR_BLOCKRE_BRACKET_BLOCKRE_TEX_BLOCKr   r   blockprocessors)
rr   r   rt   allowed_inliner   inline_patternsinlineallowed_blockblock_patternr   s
             r   extendMarkdownz"ArithmatexExtension.extendMarkdownt  s    	T""""se$$$"" VZZ(G9LMMNNzz.$77~%%""\#_#9#9O_```n$$""#4555 	K,X8Q8Q-QSYZZF&&v/BEJJJ FJJ~7T7T7TUUVV}$$  111}$$  !1222m##  ... 	P,-@388MCZCZ-Z\bdfggEI%..u6H$OOOOO	P 	Pr   )r   r   r   r   rq   r   __classcell__)r   s   @r   r   r   O  sU        22 *  *  *  *  *DP P P P P P Pr   r   c                      t          | i |S )zReturn extension.)r   )r   r%   s     r   makeExtensionr     s     ////r   )r   r   N)r   r   Nr'   F)r   r   Nr6   r'   )r   r   NN)r   r   NNFrO   )r   r   NNrQ   rO   )(r   markdownr   markdown.inlinepatternsr   markdown.blockprocessorsr   r   r0   	functoolsr   xml.etree.ElementTreer-   ElementTreerV   r   r   r   r   r   r   r   r   
deprecatedr   r!   r&   r   r$   rB   rH   rJ   rN   rE   rM   rc   re   r   r   r   rY   r   r   <module>r      sW  + +X       3 3 3 3 3 3 3 3 3 3 3 3 $ $ $ $ $ $       % % % % % % % % %       				j W a MZ<     
6 6 6 
6  
7 7 7 
7  
L L L 
L	 	 	 	   
@ 
@ 
@  
5 5 5 
5  
6 6 6 
6  
T T T 
T _d   0 ejK K K K$
H 
H 
H'q 'q 'q 'q 'qo 'q 'q 'qT> > > > >~ > > >BDP DP DP DP DP) DP DP DPN0 0 0 0 0r   