
    ͆h
                     R   S r SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r  SSKrSSKrSrS	rS
r\R"                  " S5      r\R"                  " S5      r\R"                  " S5      r\R"                  " S5      rSr\R"                  " SR/                  \R0                  S   \R0                  SS S-  \R0                  S   5      5      r " S S\5      rS r " S S5      rS rS rS r S r!S)S jr"S*S jr#S)S jr$ " S  S!\5      r% " S" S#\5      r& " S$ S%\&5      r' " S& S'\5      r(S( r)g)+a6  
SuperFences.

pymdownx.superfences
Nested Fenced Code Blocks

This is a modification of the original Fenced Code Extension.
Algorithm has been rewritten to allow for fenced blocks in blockquotes,
lists, etc.  And also , allow for special UML fences like 'flow' for flowcharts
and `sequence` for sequence diagrams.

Modified: 2014 - 2017 Isaac Muse <isaacmuse@gmail.com>
---

Fenced Code Extension for Python Markdown
=========================================

This extension adds Fenced Code Blocks to Python-Markdown.

See <https://pythonhosted.org/Markdown/extensions/fenced_code_blocks.html>
for documentation.

Original code Copyright 2007-2008 [Waylan Limberg](http://achinghead.com/).


All changes Copyright 2008-2014 The Python Markdown Project

License: [BSD](http://www.opensource.org/licenses/bsd-license.php)
    )	Extension)Preprocessor)CodeBlockProcessor)	get_attrs)utilN)> 	a  (?x)
    (?P<fence>~{3,}|`{3,})
    (?:[ \t]*\.?(?P<lang>[\w#.+-]+)(?=[\t ]|$))?                                           # Language
    (?:
        [ \t]*(\{(?P<attrs>[^\n]*)\}) |                                                    # Optional attributes or
        (?P<options>
            (?:
                (?:[ \t]*[a-zA-Z][a-zA-Z0-9_]*(?:=(?P<quot>"|').*?(?P=quot))?)(?=[\t ]|$)  # Options
            )+
        ) |
        (?P<unrecognized>
            (?:([ \t]*[^\s]+)(?=[\t ]|$))+
        )
    )?[ \t]*$
    z3^(?P<hl_lines>\d+(?:-\d+)?(?:[ \t]+\d+(?:-\d+)?)*)$zS(?P<linestart>[\d]+)(?:[ \t]+(?P<linestep>[\d]+))?(?:[ \t]+(?P<linespecial>[\d]+))?zh(?x)
    (?:
        (?P<key>[a-zA-Z][a-zA-Z0-9_]*)(?:=(?P<quot>"|')(?P<value>.*?)(?P=quot))?
    )
    z	%s[ \t]*$z^([\> ]*){}({}){}$   z([0-9]+)c                       \ rS rSrSrSrg)SuperFencesExceptionR   z=Special exception to ensure one is raised when a fence fails. N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       L/opt/services/DDDS/venv/lib/python3.13/site-packages/pymdownx/superfences.pyr   r   R   s    Gr   r   c                 r    U R                  SS5      n U R                  SS5      n U R                  SS5      n U $ )zBasic html escaping.&z&amp;<z&lt;r
   z&gt;)replace)txts    r   _escaper    V   s9     ++c7
#C
++c6
"C
++c6
"CJr   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)	CodeStash_   z
Stash code for later retrieval.

Store original fenced code here in case we were
too greedy and need to restore in an indented code
block.
c                     0 U l         g)Initialize.Nstashselfs    r   __init__CodeStash.__init__h        
r   c                 ,    [        U R                  5      $ )zLength of stash.)lenr'   r(   s    r   __len__CodeStash.__len__m   s     4::r   Nc                 <    U R                   R                  X5      nU$ )zGet the code from the key.)r'   get)r)   keydefaultcodes       r   r2   CodeStash.getr   s     zz~~c+r   c                     U R                   U	 g)zRemove the stashed code.Nr&   )r)   r3   s     r   removeCodeStash.removex   s     JJsOr   c                 $    X#4U R                   U'   g)zStore the code in the stash.Nr&   )r)   r3   r5   indent_levels       r   storeCodeStash.store}   s      .

3r   c                     0 U l         gzClear the stash.Nr&   r(   s    r   clear_stashCodeStash.clear_stash   r,   r   r&   N)r   r   r   r   r   r*   r/   r2   r8   r<   r@   r   r   r   r   r"   r"   _   s%    


/
r   r"   c                 ^   US   nUS   nUS   nU(       a  UR                  SU5        U(       a  SU S3OSnU(       a   SR                  S	R                  U5      5      OSnU(       a)  S	S	R                  S
 UR                  5        5       5      -   OSnSR                  XvU[	        U 5      5      $ )zFormat source as code blocks.classesid_valueattrsr    id=""  class="{}"r   c              3   6   #    U  H  u  pU S U S3v   M     g7fz="rH   Nr   .0kvs      r   	<genexpr>$fence_code_format.<locals>.<genexpr>        BMDAaS1#Q<M   z <pre{}{}{}><code>{}</code></pre>insertformatjoinitemsr    	sourcelanguage
class_nameoptionsmdkwargsrD   rE   rF   s	            r   fence_code_formatra      s     YGj!H7OEq*%&.xj"BH9@m""388G#45bGFKC#((BEKKMBBBQSE-44XwW]__r   c                 ^   US   nUS   nUS   nU(       a  UR                  SU5        U(       a  SU S3OSnU(       a   SR                  S	R                  U5      5      OSnU(       a)  S	S	R                  S
 UR                  5        5       5      -   OSnSR                  XvU[	        U 5      5      $ )zFormat source as div.rD   rE   rF   r   rG   rH   rI   rJ   r   c              3   6   #    U  H  u  pU S U S3v   M     g7frL   r   rM   s      r   rQ   #fence_div_format.<locals>.<genexpr>   rS   rT   z<div{}{}{}>{}</div>rU   rZ   s	            r   fence_div_formatre      s     YGj!H7OEq*%&.xj"BH9@m""388G#45bGFKC#((BEKKMBBBQSE ''5'&/RRr   c                 V   UR                   S   R                  nUR                  5        H|  u  pgSnU(       aa  UR                  S5      (       a  XsU'   M*  S[        4S[
        4S4 H0  u  pXi:X  d  M  USLd  M  U
b  U
R                  U5      c  M*  XrU'   Sn  O   U(       a  Mx  XsU'   M~     g)zHighlight validator.fenced_code_blockFzdata-hl_lineslinenums)titleNT)preprocessorsuse_pygmentsrY   
startswithRE_HL_LINESRE_LINENUMSmatch)r\   inputsr^   rF   r_   rl   rO   rP   matchedopt	validators              r   highlight_validatorru      s     ##$78EEL||G$$a$.#<z;>WYh"i8})*;yq?Q?]%&
"& #j w!H  r   c                 >    UR                  5        H	  u  pVXcU'   M     g)zDefault validator.T)rY   )r\   rq   r^   rF   r_   rO   rP   s          r   default_validatorrw      s      a r   c                 P    UR                   S   R                  5         U" XX#U5      $ )zValidator wrapper.rg   )rk   get_hl_settings)r\   rq   r^   rF   r_   rt   s         r   
_validatorrz      s+     ()99;Xwr::r   c                     U" XXBU40 UD6$ )zFormatter wrapper.r   )srcr\   r^   r_   r]   _fmtr`   s          r   
_formatterr~      s     zBA&AAr   c                 8    USL =(       d    US:H  =(       d    X:H  $ )zTest language.N*r   )r\   test_languages     r   _testr      s!     D UMS$8UH<UUr   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$ )	SuperFencesCodeExtension   z!SuperFences code block extension.c                 b   > / U l         SS// S/SS/SS/SS/S.U l        [        TU ]  " U0 UD6  g	)
r%   Fz-Disable indented code blocks - Default: Falsez2Specify custom fences. Default: See documentation.rI   zwSet class name for wrapper element. The default of CodeHilite or Highlight will be usedif nothing is set. - Default: ''z(Preserve tabs in fences - Default: Falsez,Relaxed fenced code headers - Default: False)disable_indented_code_blockscustom_fences	css_classpreserve_tabsrelaxed_headersN)superfencesconfigsuperr*   )r)   argsr`   	__class__s      r   r*   !SuperFencesCodeExtension.__init__   s]     -24c,d "VW $%OP %'UV
 	$)&)r   c                     U[         R                  " [        US9UUS.nUS:X  a  X@R                  S'   gU R                  R	                  U5        g)z@Extend SuperFences with the given name, language, and formatter.)r   nametest	formatterrt   r   r   N)	functoolspartialr   r   append)r)   r   r   rt   objs        r   extend_super_fences,SuperFencesCodeExtension.extend_super_fences   sO     %%e4@""	
 3;"%Q##C(r   c                 x   UR                  U 5        U R                  5       nU R                  R                  SS[        S[
        R                  " [        [        S9S.5        UR                  S/ 5      nU H  nUR                  S5      nUR                  S5      nUR                  S	[        5      nUR                  S
[        5      nUc  MV  Uc  M[  U R                  U[
        R                  " [        XgS9[
        R                  " [        US95        M     Xl        U R                  5         [!        5       U l        g)z7Add fenced block preprocessor to the Markdown instance.r   r   Nrt   r   r   r   classrW   rt   )r]   r}   )registerExtension
getConfigsr   rV   r   r   r   rz   ru   r2   ra   rw   r   r~   r_   patch_fenced_ruler"   r'   )	r)   r_   r   r   customr   r]   fence_formatrt   s	            r   extendMarkdown'SuperFencesCodeExtension.extendMarkdown   s    	T"" 	%!&..zEXY		
 

?B7#F::f%DG,J!::h0ABL

;0ABIJ$:((%%jZ[%%jIF $  [
r   c                    U R                  5       n[        U R                  5      nXl        Xl        U R
                  S   S   S:X  a  UR                  U R
                  S   S'   U R                  R                  R                  USS5        [        U R                  R                  5      nXl        Xl        U R                  R                  R                  R                  USS5        US	   (       ae  [        U R                  5      nXl        Xl        U R                  R                  R                  US
S5        U R                  R                  S/0 5        U R                  R                  S/SSS005        g)z
Patch Python Markdown with our own fenced block extension.

We don't attempt to protect against a user loading the `fenced_code` extension with this.
Most likely they will have issues, but they shouldn't have loaded them together in the first place :).
r   r   r   r   rg      r5   P   r   fenced_raw_blockg?@zpymdownx._bypassnormzpymdownx.highlight_enabledFN)r   SuperFencesBlockPreprocessorr_   r   	extensionr   	highlightrk   registerSuperFencesCodeBlockProcessorparserblockprocessorsSuperFencesRawBlockPreprocessorregisterExtensions)r)   r   fencedindented_code
raw_fenceds        r   r   *SuperFencesCodeExtension.patch_fenced_rule$  s5    "-dgg6Av&-7/5/?/?DQ,&&v/BBG5dggnnE%"&&&//vrJ/"8AJ &#' GG!!**:7I5QGG&&(>'?D 	""$8#9<PS]_dRe;fgr   c                 8    U R                   R                  5         gr?   )r'   r@   r(   s    r   resetSuperFencesCodeExtension.resetE  s     	

 r   )r   r_   r'   r   )r   r   r   r   r   r*   r   r   r   r   r   __classcell__r   s   @r   r   r      s'    +*$)"!HhB! !r   r   c                      ^  \ rS 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 rS rS rS rS rS rS rS rS rS rS rS rS rSS jrS rS rS rS rSrU =r $ )r   iK  z
Preprocessor to find fenced code blocks.

Because this is done as a preprocessor, it might be too greedy.
We will stash the blocks code and restore if we mistakenly processed
text from an indented code block.
z<pre%s><code%s>%s</code></pre>c                 v   > [         TU ]  U5        U R                  R                  U l        SU l        0 U l        g)r%   FN)r   r*   r_   
tab_lengthtab_lenchecked_hl_settingscodehilite_conf)r)   r_   r   s     r   r*   %SuperFencesBlockPreprocessor.__init__V  s3     	ww))#( !r   c                 8    UR                  U R                  5      $ )zNormalize whitespace.)
expandtabsr   )r)   texts     r   normalize_ws)SuperFencesBlockPreprocessor.normalize_ws^  s     t||,,r   c                 h    SR                  U Vs/ s H  o"U R                  S PM     sn5      $ s  snf )zDedent the fenced block lines.
N)rX   ws_virtual_len)r)   lineslines      r   rebuild_block*SuperFencesBlockPreprocessor.rebuild_blockc  s1     yyGt2234GHHGs   /c                    U R                   (       Gd/  SU l         SnSU l        U R                  R                   H/  nX l         UR                  5       nUR                  5       U l          O   SU R                  R                  ;   U l	        U R                  S   nU(       a  UOUS   U l        U R                  R                  SS5      U l        UR                  SS5      U l        US   U l        US	   U l        US
   U l        US   U l        US   U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  S0 5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l        UR                  SS5      U l         gg! [         a     GM  f = f)z8Check for Highlight extension to get its configurations.TN	attr_listr   r   Fextend_pygments_lang
guess_langpygments_stylerl   	noclassesri   linenums_styletablelinenums_classlinenums_specialr   language_prefixz	language-code_attr_on_pre
auto_titleauto_title_map
line_spansrI   line_anchorsanchor_linenumspygments_lang_classstripnldefault_lang)!r   highlighterr_   registeredExtensionshighlight_extget_pymdownx_highlight_settingsget_pymdownx_highlighterAttributeErrortreeprocessorsr   r   r   r2   r   r   r   r   rl   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   )r)   r   extr   s       r   ry   ,SuperFencesBlockPreprocessor.get_hl_settingsh  s    ''''+D$F#Dww33%(" @@BF'*'C'C'ED$ 4 )DGG,B,BBDNK0I*3Y9LDN#';;??3De#LD (.

3I4(PD%$\2DO"()9":D &~ 6D#K0DN":.DM"(**-=w"GD"(**-=z"JD$*JJ/A2$FD!#)::.?#MD $*JJ/A5$ID!$jju=DO"(**-=r"BD$jjr:DO &

>2 >D#)::.?#GD '-zz2G'OD$!::i6DL &

>4 @DM ( & s   %I
IIc                     SU l         SU l        SU l        SU l        SU l        SU l        / U l        SU l        SU l        0 U l	        / U l
        SU l        0 U l        SU l        g)zReset the class variables.Nr   rI   )wsws_lenr   fencelangquote_levelr5   empty_lines	fence_endr^   rD   idrF   r   r(   s    r   clear"SuperFencesBlockPreprocessor.clear  si     
		
r   c                    X-   R                  5       S:X  a3  U =R                  S-  sl        U R                  R                  X-   5        g[	        U5      U R
                  :w  a  US:w  a  U R                  5         gU R                  R                  U5      b*  UR                  S5      (       d   U R                  XX45        gSU l        U R                  R                  X-   5        g! [         a    e [         a    U R                  5          gf = f)zEvaluate a normal fence.rI   r   N)r   r   r   )stripr   r5   r   r.   r   r   r   rp   rm   process_nested_blockr   	Exception)r)   r   contentstartends        r   
eval_fence'SuperFencesBlockPreprocessor.eval_fence  s     L!R'!IIR\*W+++2JJL^^!!'*6w?Q?QR]?^?^))"uB  !DIIR\* (  

s   -C% %$DDc                    X0R                   :  a  U R                  5         gX0R                   ::  a  US:X  a3  U R                  R                  X-   5        U =R                  S-  sl        g[        U5      U R                  :  a  U R                  5         gU R                  (       a   X0R                   :  a  U R                  5         gU R                  R                  U5      b   U R                  XXE5        gSU l        U R                  R                  X-   5        gg! [         a    e [         a    U R                  5          gf = f)z#Evaluate fence inside a blockquote.rI   r   Nr   )r   r   r5   r   r   r.   r   r   rp   r   r   r   )r)   r   r   r   r   r   s         r   eval_quoted(SuperFencesBlockPreprocessor.eval_quoted  s     )))JJL,,,"}		  .  A% R4;;&

!!k4D4D&D 

%%g.:!--b5F $% 		  ./ -  ,   !JJL!s   !D $E Ec           
         XR                  U5      -   U l        SnU R                  b  XC-
  S-
  U l        U R                  U R	                  U R
                  5      U R                  U R                  U R                  U R                  U R                  U R                  (       a  U R                  O0 S9nUb>  U R                  U R                  SR                  U R
                  5      5      S-   XSU5        U R                  5         g))Process the contents of the nested block.N   )r|   r\   r_   r^   rD   rE   rF   r   )r   lastr   
line_countr   r5   r   r_   r^   rD   r   r   rF   _storerX   r   r)   r   r   r   r   r5   s         r   r   1SuperFencesBlockPreprocessor.process_nested_block  s     **733	>>%!kAoDO>>&&tyy177$(NNdjj " D KK))$))DII*>?$FUXY

r   c                 l    [        U5      nUS:  a  SnU$ XR                  :  a  U R                  S-   nU$ )z
Normalize highlight line number.

Clamp outrages numbers. Numbers out of range will be only one increment out range.
This prevents people from create massive buffers of line numbers that exceed real
number of code lines.
r   r   )intr	  )r)   numbers     r   normalize_hl_line.SuperFencesBlockPreprocessor.normalize_hl_line  s?     VA:F  oo%__q(Fr   c           
         / nU(       a  UR                  5        H  nUR                  S5       Vs/ s H  o@R                  U5      PM     nn[        U5      S:  a=  US   US   ::  a/  UR                  [	        [        US   US   S-   5      5      5        M|  M~  SUS   s=::  a  U R                  ::  d  M  O  M  UR                  U5        M     U$ s  snf )zParse the lines to highlight.-r   r   )splitr  r.   extendlistranger	  )r)   rh   r   entrye
line_ranges         r   parse_hl_lines+SuperFencesBlockPreprocessor.parse_hl_lines  s     !)AFSAQRAQA44Q7AQ
Rz?Q&!!}
15T%
1z!}q?P*Q%RS 6*Q-:4??::LL, *  Ss   Cc                 *    U(       a  [        U5      $ S$ Parse line start.r   r  )r)   	linestarts     r   parse_line_start-SuperFencesBlockPreprocessor.parse_line_start  s     "+s9~22r   c                 >    U(       a  [        U5      OSnUS:  a  U$ S$ )r  r   r   r   )r)   linestepsteps      r   parse_line_step,SuperFencesBlockPreprocessor.parse_line_step  s"     !)s8}baxt'R'r   c                 *    U(       a  [        U5      $ S$ r  r   )r)   linespecials     r   parse_line_special/SuperFencesBlockPreprocessor.parse_line_special  s     $/s;6B6r   c                 >   SnSn/ nSnU H{  nX0R                   :  a    OkU[        ;  a    O_US-  nUS:X  a4  U R                  XPR                  -  -
  nX7-  nUR                  SU-  5        OSnUS-  nUR                  U5        XW-  nM}     SR	                  U5      XS 4$ )zParse fence line.r   r   r   r   rI   N)r   PREFIX_CHARSr   r   rX   )r)   r   r   r   r   indexctab_sizes           r   parse_fence_line-SuperFencesBlockPreprocessor.parse_fence_line   s     A!4!44$aKFDy<<5<<+?@*		#.)!#		!E   wwr{DM))r   c                     SU l         SU l        / nU H5  nU[        ;  a    O*U =R                   S-  sl         UR                  U5        M7     U R	                  SR                  U5      5      n[        U5      U l        U$ )z<Parse the whitespace (blockquote syntax is counted as well).r   r   rI   )r   r   r.  r   r   rX   r.   )r)   r   r   r0  s       r   parse_whitespace-SuperFencesBlockPreprocessor.parse_whitespace9  sq     A$KK1KIIaL	  rwwr{+!"g	r   c           	      T   SnUR                  S5      (       a  UR                  S5      U l        UR                  S5      n0 U l        0 U l        SU l        0 nU(       aG  [
        R                  U5       H.  nUR                  S5      nUR                  S5      nUc  UnXtU'   M0     [        U R                  R                  5       H  nUS   " U R                  5      (       d  M  0 n	0 n
UR                  S[        R                  " [        [        S	95      n U" U R                  XIXR                  5      nU
(       a  SnU(       d  M  UR                  S
5      U l        Xl          O   U(       d"  U R$                  (       a  U R'                  U5      $ U$ ! [          a    e ["         a     Nsf = f)zGet options.Fr   r^   Nr3   valuer   rt   r   r   )groupr   r^   rF   r   
RE_OPTIONSfinditerreversedr   r   r2   r   r   rz   rw   r_   r   r   r   handle_unrecognized)r)   mokaystringvaluesm2r3   r8  r  r^   rF   rt   s               r   parse_options*SuperFencesBlockPreprocessor.parse_optionsJ  sk    776??DI#
 ))&1hhuo)=E#s 2 dnn889EV}TYY''!IIk93D3DZ[l3mn	$TYYPD
  D4%*YY{%;DN#*L! :$ ,,++A.. ,   s   FF'&F'c           	         SnU R                   (       d  U$ UR                  S5      (       a  UR                  S5      U l        0 U l        0 U l        SU l        [        U R                  R                  5       H  nUS   " U R                  5      (       d  M  0 n0 nUR                  S[        R                  " [        [        S95      n U" U R                  0 XEU R                  5      nU(       d  My  UR                  S5      U l        X@l        U R"                  (       a  XPl          O   U(       d  SU l        g! [         a    e [          a     Nef = f)	z!Handle unrecognized code headers.Fr   Nr   rt   r   r   T)r   r9  r   r^   rF   r   r<  r   r   r2   r   r   rz   rw   r_   r   r   r   )r)   r>  r?  r  r^   rF   rt   s          r   r=  0SuperFencesBlockPreprocessor.handle_unrecognizedx  s    ##K776??DI
 dnn889EV}TYY''!IIk93D3DZ[l3mn	$TYYGDGGLD
 4%*YY{%;DN#*L~~%*
! :$ DI ,   s   D55EEc           	         Sn[        UR                  S5      R                  SSU R                  -  5      5      n0 U l        0 U l        SU l        0 nU H:  u  pVUS:X  a  X`l        M  US:X  a  U R                  R                  U5        M6  XdU'   M<     UR                  S5      (       a  UR                  S5      U l
        O3U R                  (       a  U R                  R                  S	5      OS
U l
        [        U R                  R                  5       H  nUS   " U R                  5      (       d  M  0 n0 n	UR                  S[         R"                  " [$        [&        S95      n
 U
" U R                  XHXR(                  5      nU(       d  Mx  UR                  S5      U l        Xl        U R.                  (       a  Xl          O   U(       d"  U R0                  (       a  U R3                  U5      $ U$ ! [*         a    e [,         a     Nf = f)zHandle attribute list.FrF   r   r   Nr   .r   r   rI   r   rt   r   r   )r   r9  r   r   r^   rF   r   r   rD   r   r   popr<  r   r   r2   r   r   rz   rw   r_   r   r   r   r   r=  )r)   r>  r?  
attributesrA  rO   rP   r  r^   rF   rt   s              r   handle_attrs)SuperFencesBlockPreprocessor.handle_attrs  s    qwww/77cDLL>PQR

DADyc##A&q	  776??DI/3||((+DI dnn889EV}TYY''!IIk93D3DZ[l3mn	$TYYPD
 4%*YY{%;DN#*L~~%*
! :$ ,,++A.. ,   s   !G**H Hc                    SnU GH  nUR                  S5      nU R                  GcF  U R                  U5      n[        R	                  X0R
                  5      nUGb  UR                  S5      (       a  U R                  U5      nO9UR                  S5      (       a  U R                  U5      nOU R                  U5      nU(       a  UnX@R                  UR                  S5      5      -   U l        X@l        U R                  R                  S5      U l        SU l        UR                  S5      U l        [         R"                  " [$        U R                  -  5      U l        OU R)                  5         OyU R+                  U5      u  pHUS-   n	UR                  S5      n
U R                  (       a  U R-                  XHU
WU	5        O*U
S:X  a  U R/                  XHWU	5        OU R)                  5         US-  nGM     U R1                  U5      $ )z Search for nested fenced blocks.r   unrecognizedrF   r
   r   r   )rstripr   r5  RE_NESTED_FENCE_STARTrp   r   r9  r=  rK  rC  r   firstr   countr   r   recompileNESTED_FENCE_ENDr   r   r2  r  r   
reassemble)r)   r   rS  r   r   r>  r?  r   r   r   r   s              r   search_nested*SuperFencesBlockPreprocessor.search_nested  s    D ;;t$Dzz!**40 *//kkB= ww~..#77:))#003#11!4 %%'*;*;AGGAJ*G%G
"$+/77==+=(+,(%&WWW%5
)+4Dtzz4Q)R 

 #33D9ai hhsm##$$R+ucJ A%OOB< JJLQJEs v u%%r   c                     [        U R                  5      (       aG  U R                  R                  5       u  p#nUSU U/-   XS -   n[        U R                  5      (       a  MG  U$ )Reassemble text.N)r.   stackrI  r)   r   r   r   r   s        r   rW  'SuperFencesBlockPreprocessor.reassemble  sW     $**oo!%!1F3&5MVH,uT{:E $**oo r   c                 |   US   nUS   nUS   nUc  / nSn	Sn
SnSnSnU R                   (       a  SU;   a,  [        R                  US   5      nUR                  S5      nUS	 SU;   aN  [        R                  US   5      nUR                  S5      n
UR                  S5      n	UR                  S	5      nUS	 S
U;   a  US
   nUS
	 U R                  U	5      n	U R                  U
5      n
U R                  U5      nU R                  U5      nU R                  =R                  S-  sl
        U R                  U R                  U R                  U R                   U R                  U R                  U R                   U R"                  U R$                  U R&                  U R(                  U R*                  U R,                  U R.                  U R0                  U R2                  U R4                  U R6                  U R8                  U R:                  S9R=                  UUU R>                  UU
U	UUUUUU R                  R                  S9nU$ )z
Syntax highlight the code block.

If configuration is not empty, then the CodeHilite extension
is enabled, so we call into it to highlight the code.
rD   rE   rF   Nrh   ri   r!  r%  r*  rj   r   )r   r   rl   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )	rh   r!  r%  r*  rD   rE   rF   rj   code_block_count) rl   rn   rp   r9  ro   r'  r"  r+  r  r   pygments_code_blockr   r   r   r   ri   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r)   r|   r\   r^   r_   r`   rD   rE   rF   r%  r!  r*  rh   rj   r>  els                   r   r   &SuperFencesBlockPreprocessor.highlight  sF    #*%w?G 	W$%%gj&9:77:.J'W$%%gj&9:GGK0	77:.ggm4J''!(G$''1)))4	--k:&&x0..!3...**nn]]..!22..!%!:!: 00!22..** 00 $ 8 8LL**'  
( )NN#!//CC  
) 	F 	r   c           	         U R                   R                  R                  U5      nU R                  R	                  SR                  U R                  U5      X445        U R                  (       di  U R                  R                  R                  USS SR                  U R                  U R                  U5      U R                  5      U R                  5        gg)
Store the fenced blocks in the stack to be replaced when done iterating.

Store the original text in case we need to restore if we are too greedy.
{}{}r   r   {}
{}{}N)r_   	htmlStashr<   r\  r   rW   r   disabled_indentedr   r'   rR  r   r  r   r)   r[   r5   r   r   placeholders         r   r
  #SuperFencesBlockPreprocessor._storei  s     gg''--d3

6==+>KL%% NN  &&Ab!!!$**d.?.?.GS## &r   c                 h    / nUR                  S5       H  nX#-
  nUR                  XVS 5        M     U$ z0Reindent the code to where it is supposed to be.r   N)r  r   r)   r   poslevelindentedr   r/  s          r   reindent%SuperFencesBlockPreprocessor.reindent{  s:     JJt$DKEOODL) % r   c                    / nU H  n[         R                  U5      nU(       a  UR                  S5      n[        UR                  S5      5      nSnU R                  R
                  R                  US5      u  pxUbH  U R                  XxU5      n	UR                  U	5        U R                  R
                  R                  U5        Uc  UR                  U5        M  M  UR                  U5        M     U$ ),Revert a prematurely converted fenced block.r  r   NNN)FENCED_BLOCK_RErp   r9  r.   r   r'   r2   rs  r  r8   r   )
r)   r   	new_linesr   r>  r3   r;   originalrp  r5   s
             r   restore_raw_text-SuperFencesBlockPreprocessor.restore_raw_text  s     	D%%d+Aggaj"1771: $ 4 4 8 8l K'==ED$$T*NN((//4# $$T* $   &' ( r   c                 :   U R                  5         U R                  5         / U l        U R                  R	                  SS5      U l        U R                  R	                  SS5      U l        U R                  (       a  U R                  U5      nU R                  U5      $ )Search for fenced blocks.r   Fr   )	ry   r   r\  r   r2   ri  r   r{  rX  r)   r   s     r   run SuperFencesBlockPreprocessor.run  sz     	


!%1OQV!W![[___eD))%0E!!%((r   )/r   r   rF   r   r   r   rD   r5   r   r   r   r   ri  r   r   r   r   rR  r   r   r   r   r   r   r   r  r   r	  r   ri   r   r   r   r   r^   r   r   r   r   r   r\  r   r   rl   r   r   r   )rI   rI   NN)!r   r   r   r   r   	CODE_WRAPr*   r   r   ry   r   r   r  r   r  r  r"  r'  r+  r2  r5  rC  r=  rK  rX  rW  r   r
  rs  r{  r  r   r   r   s   @r   r   r   K  s     1I"-
I
)AV$+./>, 3
(7
*2",\#J-^?&B	Ob$4) )r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   i  z@Special class for preserving tabs before normalizing whitespace.c                     XR                  U5      -   U l        SR                  U R                  5      nU R	                  US-   XSU5        U R                  5         g)r  r   N)r   r  rX   r5   r
  r   r  s         r   r   4SuperFencesRawBlockPreprocessor.process_nested_block  sH     **733	yy#D4Kc2

r   c                 l   U R                   R                  R                  S5      nU R                  R	                  SR                  U R                  U5      X445        U R                  R                  R                  USS SR                  U R                  XR                  5      U R                  5        g)re  rI   rf  r   r   rg  N)r_   rh  r<   r\  r   rW   r   r   r'   rR  r  r   rj  s         r   r
  &SuperFencesRawBlockPreprocessor._store  s     gg''--b1

6==+>KL"""djj&))<	
r   c                 "   [        U R                  5      (       at  U R                  R                  5       u  p#nUSU UR                  [        R
                  [        S5      SS [        -   /-   XS -   n[        U R                  5      (       a  Mt  U$ )r[  Nr   r   )r.   r\  rI  r   md_utilSTXSOHEOTr]  s        r   rW  *SuperFencesRawBlockPreprocessor.reassemble  sy     $**oo!%!1F3&5MV^^GKKa%H"%MPS%S$TTW\]aWbbE $**oo r   c                     U R                  5         U R                  5         / U l        U R                  R	                  SS5      U l        U R                  U5      $ )r~  r   F)ry   r   r\  r   r2   ri  rX  r  s     r   r  #SuperFencesRawBlockPreprocessor.run  sJ     	


!%1OQV!W!!%((r   )ri  r  r\  N)
r   r   r   r   r   r   r
  rW  r  r   r   r   r   r   r     s    J
 	)r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	r   i  z_Process indented code blocks to see if we accidentally processed its content as a fenced block.c                     g)z-Test method that is one day to be deprecated.Tr   )r)   parentblocks      r   r   "SuperFencesCodeBlockProcessor.test  s     r   c                     / nUR                  S5       H  nX#-
  nUR                  XVS 5        M     SR                  U5      $ rn  )r  r   rX   ro  s          r   rs  &SuperFencesCodeBlockProcessor.reindent  sD     JJt$DKEOODL) % yy""r   c                 "   / nUR                  S5       H  n[        R                  U5      nU(       a  UR                  S5      n[	        UR                  S5      5      nSnU R
                  R                  R                  US5      u  pxUbH  U R                  XxU5      n	UR                  U	5        U R
                  R                  R                  U5        Uc  UR                  U5        M  M  UR                  U5        M     SR                  U5      $ )rv  r   r  r   Nrw  )r  rx  rp   r9  r.   r   r'   r2   rs  r   r8   rX   )
r)   r  	new_blockr   r>  r3   r;   rz  rp  r5   s
             r   revert_greedy_fences2SuperFencesCodeBlockProcessor.revert_greedy_fences  s     	KK%D%%d+Aggaj"1771: $ 4 4 8 8l K'==ED$$T*NN((//4# $$T* $   &' &( yy##r   c                 0   SnU R                   R                  SS5      (       dr  [        R                  " XUS   5      nU(       aQ  U R                   R                  SS5      (       a  U R	                  US   5      US'   [        R
                  " XU5      SLnU$ )zLook for and parse code block.Fr   r   nestedT)r   r2   r   r   r  r  )r)   r  blockshandleds       r   r  !SuperFencesCodeBlockProcessor.run  s     {{=uEE(--dF1IFG;;??8T22 $ 9 9&) DF1I,00vFeSr   r   N)
r   r   r   r   r   r   rs  r  r  r   r   r   r   r   r     s    i
#$4r   r   c                      [        U 0 UD6$ )zReturn extension.)r   )r   r`   s     r   makeExtensionr    s     $T4V44r   rB   )rI   rI   NNrI   N)*r   markdown.extensionsr   markdown.preprocessorsr   markdown.blockprocessorsr   markdown.extensions.attr_listr   markdownr   r  r   rT  r  r  r.  rU  rQ  rn   ro   r:  rV  rW   HTML_PLACEHOLDERrx  r   r   r    r"   ra   re   ru   rw   rz   r~   r   r   r   r   r   r  r   r   r   <module>r     sP  : * / 7 3 $  	

 $ jjOPjjopZZ
   **    #  2&4  $H9 H& &R`"S".;BVl!y l!^^	)< ^	)B-)&B -)`6$6 6r5r   