
    $gl&                        d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	 ddl
Z
dZdZd	Zed
z  Zd                    eee	          Zd                    eeee	          ZdZ e
j        ee
j                  Z e
j        e          Z e
j        e          Z e
j        d          Z e
j        d          Z G d d          Z G d de          Z G d de          Z G d de          Zd ZdS )a  
Critic.

pymdownx.critic
Parses critic markup and outputs the file in a more visual HTML.
Must be the last extension loaded.

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)Preprocessor)Postprocessor)STXETXNz
czjqqkd:%sz[0-9]+z{stx}(?P<key>{key}){etx})keystxetxzY(?x)
(?:
    (?P<block>\<p\>(?P<block_keys>(?:{stx}{key}{etx})+)\</p\>) |
    {single}
)
)r
   singler   r   aI  (?x)
((?P<critic>(?P<open>\{)
    (?:
        (?P<ins_open>\+{2})
        (?P<ins_text>.*?)
        (?P<ins_close>\+{2})

      | (?P<del_open>\-{2})
        (?P<del_text>.*?)
        (?P<del_close>\-{2})

      | (?P<mark_open>\={2})
        (?P<mark_text>.*?)
        (?P<mark_close>\={2})

      | (?P<comment>
            (?P<com_open>\>{2})
            (?P<com_text>.*?)
            (?P<com_close>\<{2})
        )

      | (?P<sub_open>\~{2})
        (?P<sub_del_text>.*?)
        (?P<sub_mid>\~\>)
        (?P<sub_ins_text>.*?)
        (?P<sub_close>\~{2})
    )
(?P<close>\})))
z-((?:ins|del|mark)\s+)(class=([\'"]))(.*?)(\3)z^(?:\r?\n){2,}$c                   8    e Zd ZdZd Zd Zd	dZd Zd Zd Z	dS )
CriticStashzStash critic marks until ready.c                 0    || _         i | _        d| _        dS )Initialize.r   N)	stash_keystashcount)selfr   s     O/var/www/html/netbox-4.1.3/venv/lib/python3.11/site-packages/pymdownx/critic.py__init__zCriticStash.__init__Y   s     #



    c                 *    t          | j                  S )zGet length of stash.)lenr   r   s    r   __len__zCriticStash.__len__`   s    4:r   Nc                 <    | j                             ||          }|S )z&Get the specified item from the stash.)r   get)r   r
   defaultcodes       r   r   zCriticStash.getd   s     z~~c7++r   c                     | j         |= dS )z)Remove the specified item from the stash.N)r   )r   r
   s     r   removezCriticStash.removej   s     JsOOOr   c                     | j         t          | j                  z  }|| j        |<   | xj        dz  c_        t          |z   t
          z   S )z`
        Store the code in the stash with the placeholder.

        Return placeholder.
           )r   strr   r   SOHEOT)r   r    r
   s      r   storezCriticStash.storeo   s@     ns4:.
3

a

Sy3r   c                 "    i | _         d| _        dS )zClear the stash.r   N)r   r   r   s    r   clearzCriticStash.clearz   s     



r   )N)
__name__
__module____qualname____doc__r   r   r   r"   r(   r*    r   r   r   r   V   sy        ))         
	 	 	    r   r   c                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )CriticsPostprocessorz8Handle cleanup on post process for viewing critic marks.c                 V    t                                                       || _        dS r   Nsuperr   critic_stashr   r6   	__class__s     r   r   zCriticsPostprocessor.__init__   )     	(r   c                 l    d}|                     d          }|| j                            |          }|S )zaReplace all critic tags in the paragraph block `<p>(critic del close)(critic ins close)</p>` etc.Nr
   )groupr6   r   )r   mcontentr
   s       r   
subrestorezCriticsPostprocessor.subrestore   s6    ggenn?'++C00Gr   c                 4   d|                     d                              d          v r|                     d          S |                     d          |                     d          z   |                     d          z   dz   |                     d          z   S )	zHandle block edits.break    r   r$      z block   )r;   splitr   r<   s     r   
block_editzCriticsPostprocessor.block_edit   sy     aggajj&&s++++771::771::

*QWWQZZ7(BQWWQZZOOr   c                 p   d}|                     d          Vt                              | j        |                     d                    }| t                              | j        |          }n1| j                            |                     d                    }||}||n|                     d          S )z-Replace placeholders with actual critic tags.N
block_keysr
   r   )r;   RE_CRITIC_SUB_PLACEHOLDERsubr>   RE_CRITIC_BLOCKrG   r6   r   )r   r<   r=   texts       r   restorezCriticsPostprocessor.restore   s     77<  ,/33!6!6 G ")--dowGG$((88D!-ww1771::=r   c                 F    t                               | j        |          }|S )zReplace critic placeholders.)RE_CRITIC_PLACEHOLDERrK   rN   r   rM   s     r   runzCriticsPostprocessor.run   s      %((t<<r   )
r+   r,   r-   r.   r   r>   rG   rN   rR   __classcell__r8   s   @r   r1   r1      s}        BB) ) ) ) )  P P P> > >       r   r1   c                   T     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
dd
Zd Z xZS )CriticViewPreprocessorz0Handle viewing critic marks in Markdown content.c                 V    t                                                       || _        dS r3   r4   r7   s     r   r   zCriticViewPreprocessor.__init__   r9   r   c                     t                               |          rd| j                            d          z  S | j                            d          |z   | j                            d          z   S )zHandle critic inserts.z

%s

z&<ins class="critic break">&nbsp;</ins>z<ins class="critic">z</ins>RE_BLOCK_SEPmatchr6   r(   rQ   s     r   _inszCriticViewPreprocessor._ins   ss     d## 	d$"3"9"9:b"c"ccc##$:;;##H--.	
r   c                     t                               |          r| j                            d          S | j                            d          |z   | j                            d          z   S )zHandle critic deletes.z&<del class="critic break">&nbsp;</del>z<del class="critic">z</del>rY   rQ   s     r   _delzCriticViewPreprocessor._del   sn     d## 	U$**+STTT##$:;;##H--.	
r   c                 r    | j                             d          |z   | j                             d          z   S )zHandle critic marks.z<mark class="critic">z</mark>)r6   r(   rQ   s     r   _markzCriticViewPreprocessor._mark   s?     ##$;<<##I../	
r   c                 l    | j                             d|                     |d          z   dz             S )zHandle critic comments.z<span class="critic comment">T)strip_nlz</span>)r6   r(   html_escaperQ   s     r   _commentzCriticViewPreprocessor._comment   sE     ##/   556 	
r   c                    |                     d          r(|                     |                     d                    S |                     d          r(|                     |                     d                    S |                     d          rQ|                     |                     d                    |                     |                     d                    z   S |                     d          r(|                     |                     d	                    S |                     d
          r(|                     |                     d                    S dS )z:Insert appropriate HTML to tags to visualize Critic marks.ins_openins_textdel_opendel_textsub_opensub_del_textsub_ins_text	mark_open	mark_textcom_opencom_textN)r;   r\   r^   r`   rd   rF   s     r   critic_viewz"CriticViewPreprocessor.critic_view   s,    77: 	699QWWZ00111WWZ   
	699QWWZ00111WWZ   	6		!''.1122		!''.11223 WW[!! 	6::aggk22333WWZ   	6==!4!4555	6 	6r   c                    | j         d         dk    }|                    d          r|r|                    d          ndS |                    d          r|rdn|                    d          S |                    d          r|                    d	          S |                    d
          rdS |                    d          r,|r|                    d          n|                    d          S dS )z
        Normal critic parser.

        Either removes accepted or rejected critic marks and replaces with the opposite.
        Comments are removed and marks are replaced with their content.
        modeacceptrf   rg    rh   ri   rm   rn   ro   rj   rl   rk   N)configr;   )r   r<   rt   s      r   critic_parsez#CriticViewPreprocessor.critic_parse   s     V$077: 		R*08177:&&&b8WWZ   	R822QWWZ%8%88WW[!! 	R77;'''WWZ   	R2WWZ   	R.4Q177>***!''.:Q:QQ	R 	Rr   Fc                     |                     dd          }|                     dd          }|                     dd          }|                     dd          }|                     d	|sd
nd          }|S )zBasic html escaping.&z&amp;<z&lt;>z&gt;"z&quot;
z<br>rB   )replace)r   txtrb   s      r   rc   z"CriticViewPreprocessor.html_escape	  sq     kk#w''kk#v&&kk#v&&kk#x((kk$h ?C@@
r   c                     | j         d         dk    r| j        }n| j        }t                              |d                    |                    }|                    d          S )zProcess critic marks.rs   viewr}   )rv   rq   rw   	RE_CRITICrK   joinrE   )r   lines	processorrM   s       r   rR   zCriticViewPreprocessor.run  s[     ;v&(((II)I }}Y		%(8(899zz$r   )F)r+   r,   r-   r.   r   r\   r^   r`   rd   rq   rw   rc   rR   rS   rT   s   @r   rV   rV      s        ::) ) ) ) )	
 	
 	
	
 	
 	

 
 
	
 	
 	
6 6 6"R R R&                r   rV   c                   .     e Zd ZdZ fdZd Zd Z xZS )CriticExtensionzCritic extension.c                 V    ddgddgd| _          t                      j        |i | dS )r   r   zFCritic mode to run in ('view', 'accept', or 'reject') - Default: view FzIRaw view keeps the output as the raw markup for view mode - Default False)rs   raw_viewN)rv   r5   r   )r   argskwargsr8   s      r   r   zCriticExtension.__init__%  sI     ef kl
 

 	$)&)))))r   c                    |                     |            t          t                    | _        t	          | j                  }t          | j                  }|                                 |_        |j        	                    |dd           |j
        	                    |dd           |                    dgi            dS )zRegister the extension.criticg?@zcritic-post   zpymdownx._bypassnormN)registerExtensionr   
CRITIC_KEYr6   r1   rV   
getConfigsrv   preprocessorsregisterpostprocessorsregisterExtensions)r   mdpostr   s       r   extendMarkdownzCriticExtension.extendMarkdown/  s     	T"""'
33#D$566'(9::))
!!&(D999
""4;;;
56;;;;;r   c                 8    | j                                          dS )zClear stash.N)r6   r*   r   s    r   resetzCriticExtension.reset;  s     	!!!!!r   )r+   r,   r-   r.   r   r   r   rS   rT   s   @r   r   r   "  s\        * * * * *
< 
< 
<" " " " " " "r   r   c                      t          | i |S )zReturn extension.)r   )r   r   s     r   makeExtensionr   A  s     D+F+++r   )r.   markdownr   markdown.preprocessorsr   markdown.postprocessorsr   markdown.utilr   r   rer&   r'   r   CRITIC_PLACEHOLDERformatSINGLE_CRITIC_PLACEHOLDERCRITIC_PLACEHOLDERSALL_CRITICScompileDOTALLr   rP   rJ   rL   rZ   r   r1   rV   r   r   r/   r   r   <module>r      s   2       / / / / / / 1 1 1 1 1 1 " " " " " " " " 				
)+ 7>> ?   
 F#<    < BJ{BI..	"
#677 &BJ'@AA "*MNNrz,--( ( ( ( ( ( ( (V. . . . .= . . .bm  m  m  m  m \ m  m  m `" " " " "i " " ">, , , , ,r   