
    ͆hl&                        S r SSKJr  SSKJr  SSKJr  SSKJrJ	r	  SSK
r
SrSrS	r\S
-  rSR                  \\\	S9rSR                  \\\\	S9rSr\
R&                  " \\
R(                  5      r\
R&                  " \5      r\
R&                  " \5      r\
R&                  " S5      r\
R&                  " S5      r " S S5      r " S S\5      r " S S\5      r " S S\5      rS rg)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                   @    \ rS rSrSrS rS rSS jrS rS r	S	 r
S
rg)CriticStashV   zStash critic marks until ready.c                 ,    Xl         0 U l        SU l        g)Initialize.r   N)	stash_keystashcount)selfr   s     G/opt/services/DDDS/venv/lib/python3.13/site-packages/pymdownx/critic.py__init__CriticStash.__init__Y   s     #

    c                 ,    [        U R                  5      $ )zGet length of stash.)lenr   r   s    r   __len__CriticStash.__len__`   s    4::r   Nc                 <    U R                   R                  X5      nU$ )z&Get the specified item from the stash.)r   get)r   r
   defaultcodes       r   r!   CriticStash.getd   s     zz~~c+r   c                     U R                   U	 g)z)Remove the specified item from the stash.N)r   )r   r
   s     r   removeCriticStash.removej   s     JJsOr   c                     U R                   [        U R                  5      -  nXR                  U'   U =R                  S-  sl        [        U-   [
        -   $ )zH
Store the code in the stash with the placeholder.

Return placeholder.
   )r   strr   r   SOHEOT)r   r#   r
   s      r   storeCriticStash.storeo   s@     nns4::.

3

a
Sy3r   c                      0 U l         SU l        g)zClear the stash.r   N)r   r   r   s    r   clearCriticStash.clearz   s     

r   )r   r   r   )N)__name__
__module____qualname____firstlineno____doc__r   r   r!   r&   r-   r0   __static_attributes__ r   r   r   r   V   s#    )
	r   r   c                   D   ^  \ rS rSrSrU 4S jrS rS rS rS r	Sr
U =r$ )	CriticsPostprocessor   z8Handle cleanup on post process for viewing critic marks.c                 .   > [         TU ]  5         Xl        gr   Nsuperr   critic_stashr   r@   	__class__s     r   r   CriticsPostprocessor.__init__        	(r   c                 h    SnUR                  S5      nUb  U R                  R                  U5      nU$ )zaReplace all critic tags in the paragraph block `<p>(critic del close)(critic ins close)</p>` etc.Nr
   )groupr@   r!   )r   mcontentr
   s       r   
subrestoreCriticsPostprocessor.subrestore   s4    ggen?''++C0Gr   c                     SUR                  S5      R                  S5      ;   a  UR                  S5      $ UR                  S5      UR                  S5      -   UR                  S5      -   S-   UR                  S5      -   $ )	zHandle block edits.break    r   r)      z block   )rF   splitr   rG   s     r   
block_editCriticsPostprocessor.block_edit   sg     aggaj&&s++771:771:
*QWWQZ7(BQWWQZOOr   c                 Z   SnUR                  S5      bS  [        R                  U R                  UR                  S5      5      nUb   [        R                  U R
                  U5      nO/U R                  R                  UR                  S5      5      nUb  UnUb  U$ UR                  S5      $ )z-Replace placeholders with actual critic tags.N
block_keysr
   r   )rF   RE_CRITIC_SUB_PLACEHOLDERsubrI   RE_CRITIC_BLOCKrS   r@   r!   )r   rG   rH   texts       r   restoreCriticsPostprocessor.restore   s     77< ,/33!6G ")--doowG$$((8D!-w=1771:=r   c                 F    [         R                  U R                  U5      nU$ )zReplace critic placeholders.)RE_CRITIC_PLACEHOLDERrX   r[   r   rZ   s     r   runCriticsPostprocessor.run   s     %((t<r   r@   )r2   r3   r4   r5   r6   r   rI   rS   r[   r`   r7   __classcell__rB   s   @r   r:   r:      s%    B)P>  r   r:   c                   `   ^  \ rS rSrSrU 4S jrS rS rS rS r	S r
S	 rSS
 jrS rSrU =r$ )CriticViewPreprocessor   z0Handle viewing critic marks in Markdown content.c                 .   > [         TU ]  5         Xl        gr=   r>   rA   s     r   r   CriticViewPreprocessor.__init__   rD   r   c                     [         R                  U5      (       a  SU R                  R                  S5      -  $ U R                  R                  S5      U-   U R                  R                  S5      -   $ )zHandle critic inserts.z

%s

z&<ins class="critic break">&nbsp;</ins>z<ins class="critic">z</ins>RE_BLOCK_SEPmatchr@   r-   r_   s     r   _insCriticViewPreprocessor._ins   sm     d##$"3"3"9"9:b"ccc##$:;##H-.	
r   c                     [         R                  U5      (       a  U R                  R                  S5      $ U R                  R                  S5      U-   U R                  R                  S5      -   $ )zHandle critic deletes.z&<del class="critic break">&nbsp;</del>z<del class="critic">z</del>rk   r_   s     r   _delCriticViewPreprocessor._del   sh     d##$$**+STT##$:;##H-.	
r   c                 v    U R                   R                  S5      U-   U R                   R                  S5      -   $ )zHandle critic marks.z<mark class="critic">z</mark>)r@   r-   r_   s     r   _markCriticViewPreprocessor._mark   s?     ##$;<##I./	
r   c                 `    U R                   R                  SU R                  USS9-   S-   5      $ )zHandle critic comments.z<span class="critic comment">T)strip_nlz</span>)r@   r-   html_escaper_   s     r   _commentCriticViewPreprocessor._comment   s@     ##/   56	
r   c                 b   UR                  S5      (       a   U R                  UR                  S5      5      $ UR                  S5      (       a   U R                  UR                  S5      5      $ UR                  S5      (       aA  U R                  UR                  S5      5      U R                  UR                  S5      5      -   $ UR                  S5      (       a   U R                  UR                  S	5      5      $ UR                  S
5      (       a   U R	                  UR                  S5      5      $ g)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)rF   rn   rq   rt   ry   rR   s     r   critic_view"CriticViewPreprocessor.critic_view   s     77:99QWWZ011WWZ  99QWWZ011WWZ  		!''.12		!''.123 WW[!!::aggk233WWZ  ==!455 !r   c                    U R                   S   S:H  nUR                  S5      (       a  U(       a  UR                  S5      $ S$ UR                  S5      (       a  U(       a  S$ UR                  S5      $ UR                  S5      (       a  UR                  S	5      $ UR                  S
5      (       a  gUR                  S5      (       a)  U(       a  UR                  S5      $ UR                  S5      $ g)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acceptr|   r}    r~   r   r   r   r   r   r   r   N)configrF   )r   rG   r   s      r   critic_parse#CriticViewPreprocessor.critic_parse   s     V$077:*0177:&8b8WWZ  28QWWZ%88WW[!!77;''WWZ  WWZ  .4177>*Q!''.:QQ !r   c                     UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	U(       d  S
5      nU$ S5      nU$ )zBasic html escaping.&z&amp;<z&lt;>z&gt;"z&quot;
z<br>rN   )replace)r   txtrw   s      r   rx   "CriticViewPreprocessor.html_escape	  sk     kk#w'kk#v&kk#v&kk#x(kk$h@
 =@@
r   c                     U R                   S   S:X  a  U R                  nOU R                  n[        R	                  USR                  U5      5      nUR                  S5      $ )zProcess critic marks.r   viewr   )r   r   r   	RE_CRITICrX   joinrQ   )r   lines	processorrZ   s       r   r`   CriticViewPreprocessor.run  sU     ;;v&(((I))I }}Y		%(89zz$r   rb   )F)r2   r3   r4   r5   r6   r   rn   rq   rt   ry   r   r   rx   r`   r7   rc   rd   s   @r   rf   rf      s9    :)	
	

	
6"R&   r   rf   c                   8   ^  \ rS rSrSrU 4S jrS rS rSrU =r	$ )CriticExtensioni"  zCritic extension.c                 B   > SS/SS/S.U l         [        TU ]  " U0 UD6  g)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)r   raw_viewN)r   r?   r   )r   argskwargsrB   s      r   r   CriticExtension.__init__%  s4     ef kl

 	$)&)r   c                 f   UR                  U 5        [        [        5      U l        [	        U R                  5      n[        U R                  5      nU R                  5       Ul        UR                  R                  USS5        UR                  R                  USS5        UR                  S/0 5        g)zRegister the extension.criticg?@zcritic-post   zpymdownx._bypassnormN)registerExtensionr   
CRITIC_KEYr@   r:   rf   
getConfigsr   preprocessorsregisterpostprocessorsregisterExtensions)r   mdpostr   s       r   extendMarkdownCriticExtension.extendMarkdown/  s     	T"'
3#D$5$56'(9(9:)
!!&(D9
""4;
56;r   c                 8    U R                   R                  5         g)zClear stash.N)r@   r0   r   s    r   resetCriticExtension.reset;  s     	!r   )r   r@   )
r2   r3   r4   r5   r6   r   r   r   r7   rc   rd   s   @r   r   r   "  s    *
<" "r   r   c                      [        U 0 UD6$ )zReturn extension.)r   )r   r   s     r   makeExtensionr   A  s     D+F++r   )r6   markdownr   markdown.preprocessorsr   markdown.postprocessorsr   markdown.utilr   r   rer+   r,   r   CRITIC_PLACEHOLDERformatSINGLE_CRITIC_PLACEHOLDERCRITIC_PLACEHOLDERSALL_CRITICScompileDOTALLr   r^   rW   rY   rl   r   r:   rf   r   r   r8   r   r   <module>r      s  2  / 1 " 	
)+ 7>> ?  
 F#<   < JJ{BII.	

#67 JJ'@A **MNzz,-( (V.= .bm \ m `"i ">,r   