Ë
    ÁjÂ4  ã                  ó  — 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
mZmZ e
r	dd	lmc mZ 	 dd
lmZ ddlmZmZ ddlmZ ddlmZ dZdd„Z G d„ d«      Z G d„ de«      Z G d„ de«      Zd„ Zy	# e$ r dZY Œ1w xY w)z¨
Adds code/syntax highlighting to standard Python-Markdown code blocks.

See the [documentation](https://Python-Markdown.github.io/extensions/code_hilite)
for details.
é    )Úannotationsé   )Ú	Extensioné   )ÚTreeprocessor)ÚparseBoolValue)ÚTYPE_CHECKINGÚCallableÚAnyN)Ú	highlight)Úget_lexer_by_nameÚguess_lexer)Úget_formatter_by_name)ÚClassNotFoundTFc                ó|   — | sg S 	 t        t        t        | j                  «       «      «      S # t        $ r g cY S w xY w)zÊSupport our syntax for emphasizing certain lines of code.

    `expr` should be like '1 2' to emphasize lines 1 and 2 of a code block.
    Returns a list of integers, the line numbers to emphasize.
    )ÚlistÚmapÚintÚsplitÚ
ValueError)Úexprs    úQ/var/www/html/venv/lib/python3.12/site-packages/markdown/extensions/codehilite.pyÚparse_hl_linesr   *   s=   € ñ Øˆ	ðÜ”Cœ˜TŸZ™Z›\Ó*Ó+Ð+øÜò ØŠ	ðús   †&- ­;º;c                  ó*   — e Zd ZdZdd„Zddd„Zd	d„Zy)
Ú
CodeHiliteau	  
    Determine language of source code, and pass it on to the Pygments highlighter.

    Usage:

    ```python
    code = CodeHilite(src=some_code, lang='python')
    html = code.hilite()
    ```

    Arguments:
        src: Source string or any object with a `.readline` attribute.

    Keyword arguments:
        lang (str): String name of Pygments lexer to use for highlighting. Default: `None`.
        guess_lang (bool): Auto-detect which lexer to use.
            Ignored if `lang` is set to a valid value. Default: `True`.
        use_pygments (bool): Pass code to Pygments for code highlighting. If `False`, the code is
            instead wrapped for highlighting by a JavaScript library. Default: `True`.
        pygments_formatter (str): The name of a Pygments formatter or a formatter class used for
            highlighting the code blocks. Default: `html`.
        linenums (bool): An alias to Pygments `linenos` formatter option. Default: `None`.
        css_class (str): An alias to Pygments `cssclass` formatter option. Default: 'codehilite'.
        lang_prefix (str): Prefix prepended to the language. Default: "language-".

    Other Options:

    Any other options are accepted and passed on to the lexer and formatter. Therefore,
    valid options include any options which are accepted by the `html` formatter or
    whichever lexer the code's language uses. Note that most lexers do not have any
    options. However, a few have very useful options, such as PHP's `startinline` option.
    Any invalid options are ignored without error.

    * **Formatter options**: <https://pygments.org/docs/formatters/#HtmlFormatter>
    * **Lexer Options**: <https://pygments.org/docs/lexers/>

    Additionally, when Pygments is enabled, the code's language is passed to the
    formatter as an extra option `lang_str`, whose value being `{lang_prefix}{lang}`.
    This option has no effect to the Pygments' builtin formatters.

    Advanced Usage:

    ```python
    code = CodeHilite(
        src = some_code,
        lang = 'php',
        startinline = True,      # Lexer option. Snippet does not start with `<?php`.
        linenostart = 42,        # Formatter option. Snippet starts on line 42.
        hl_lines = [45, 49, 50], # Formatter option. Highlight lines 45, 49, and 50.
        linenos = 'inline'       # Formatter option. Avoid alignment problems.
    )
    html = code.hilite()
    ```

    c                ó†  — || _         |j                  dd «      | _        |j                  dd«      | _        |j                  dd«      | _        |j                  dd«      | _        |j                  dd«      | _        d	|vr|j                  d
d «      |d	<   d|vr|j                  dd«      |d<   d|vrd|d<   d|d<   || _        y )NÚlangÚ
guess_langTÚuse_pygmentsÚlang_prefixú	language-Úpygments_formatterÚhtmlÚlinenosÚlinenumsÚcssclassÚ	css_classÚ
codehiliteÚwrapcodeFÚfull)ÚsrcÚpopr   r   r   r    r"   Úoptions)Úselfr+   r-   s      r   Ú__init__zCodeHilite.__init__s   sÄ   € ØˆŒØ '§¡¨F°DÓ 9ˆŒ	Ø '§¡¨L¸$Ó ?ˆŒØ")§+¡+¨n¸dÓ"CˆÔØ '§¡¨M¸;Ó GˆÔØ29·+±+Ð>RÐTZÓ2[ˆÔà˜GÑ#Ø!(§¡¨Z¸Ó!>ˆG�IÑØ˜WÑ$Ø")§+¡+¨k¸<Ó"HˆG�JÑØ˜WÑ$à"&ˆG�JÑàˆ�‰àˆ�ó    c                óf  — | j                   j                  d«      | _         | j                  €|r| j                  «        t        rØ| j
                  rÌ	 t        | j                  fi | j                  ¤Ž}| j                  s|j                  d   | _        | j                  › | j                  › �}t        | j                  t        «      r"	 t!        | j                  fi | j                  ¤Ž}n | j                  dd|i| j                  ¤Ž}t%        | j                   ||«      S | j                   j'                  dd«      }|j'                  dd«      }|j'                  dd	«      }|j'                  d
d«      }g }| j                  r5|j)                  dj+                  | j                  | j                  «      «       | j                  d   r|j)                  d«       d}|r dj+                  dj-                  |«      «      }dj+                  | j                  d   ||«      S # t        $ rl 	 | j                  r!t        | j                   fi | j                  ¤Ž}nt        di | j                  ¤Ž}n$# t        $ r t        di | j                  ¤Ž}Y nw xY wY �Œw xY w# t"        $ r t!        di | j                  ¤Ž}Y �Œ©w xY w)a6  
        Pass code to the [Pygments](https://pygments.org/) highlighter with
        optional line numbers. The output should then be styled with CSS to
        your liking. No styles are applied by default - only styling hooks
        (i.e.: `<span class="k">`).

        returns : A string of html.

        Ú
r   Úlang_strÚ&ú&amp;Ú<ú&lt;Ú>ú&gt;Ú"z&quot;z{}{}r$   r%   Ú z class="{}"Ú z)<pre class="{}"><code{}>{}
</code></pre>
r&   )Útext)r#   © )r+   Ústripr   Ú_parseHeaderÚpygmentsr   r   r-   r   r   r   Úaliasesr    Ú
isinstancer"   Ústrr   r   r   ÚreplaceÚappendÚformatÚjoin)r.   ÚshebangÚlexerr3   Ú	formatterÚtxtÚclassesÚ	class_strs           r   ÚhilitezCodeHilite.hilite‡   sP  € ð —8‘8—>‘> $Ó'ˆŒà�9‰9Ð¡Ø×ÑÔå˜×)Ò)ð	FÜ)¨$¯)©)ÑD°t·|±|ÑD�ð —9’9à!ŸM™M¨!Ñ,�”	Ø×*Ñ*Ð+¨D¯I©I¨;Ð7ˆHÜ˜$×1Ñ1´3Ô7ðNÜ 5°d×6MÑ6MÑ ^ÐQU×Q]ÑQ]Ñ ^‘Ið 4˜D×3Ñ3ÑV¸XÐVÈÏÉÑV�	Ü˜TŸX™X u¨iÓ8Ð8ð —(‘(×"Ñ" 3¨Ó0ˆCØ—+‘+˜c 6Ó*ˆCØ—+‘+˜c 6Ó*ˆCØ—+‘+˜c 8Ó,ˆCØˆGØ�yŠyØ—‘˜vŸ}™}¨T×-=Ñ-=¸t¿y¹yÓIÔJØ�|‰|˜IÒ&Ø—‘˜zÔ*ØˆIÙØ)×0Ñ0°·±¸'Ó1BÓC�	Ø@×GÑGØ—‘˜ZÑ(ØØóð øôE ò FðFØ—’Ü +¨D¯H©HÑ E¸¿¹Ñ E™ä 1Ñ I¸D¿L¹LÑ I˜ùÜ!ò FÜ-ÑE¸¿¹ÑE’EðFýðFûô %ò NÜ 5Ñ MÀÇÁÑ M“IðNúsI   Á H Ã J È	JÈ AI#É"JÉ#JÊJÊJÊJÊ
JÊJ0Ê/J0c                óš  — ddl }| j                  j                  d«      }|j                  d«      }|j	                  d|j
                  «      }|j                  |«      }|rŸ	 |j                  d«      j                  «       | _	        |j                  d«      r|j                  d|«       | j                  d   € |j                  d«      rd	| j                  d<   t        |j                  d
«      «      | j                  d
<   n|j                  d|«       dj                  |«      j                  d«      | _        y# t        $ r
 d| _	        Y ŒÄw xY w)aP  
        Determines language of a code block from shebang line and whether the
        said line should be removed or left in place. If the shebang line
        contains a path (even a single /) then it is assumed to be a real
        shebang line and left alone. However, if no path is given
        (e.i.: `#!python` or `:::python`) then it is assumed to be a mock shebang
        for language identification of a code fragment and removed from the
        code block prior to processing for code highlighting. When a mock
        shebang (e.i: `#!python`) is found, line numbering is turned on. When
        colons are found in place of a shebang (e.i.: `:::python`), line
        numbering is left in the current state - off by default.

        Also parses optional list of highlight lines, like:

            :::python hl_lines="1 3"
        r   Nr2   aœ  
            (?:(?:^::+)|(?P<shebang>^[#]!)) # Shebang or 2 or more colons
            (?P<path>(?:/\w+)*[/ ])?        # Zero or 1 path
            (?P<lang>[\w#.+-]*)             # The language
            \s*                             # Arbitrary whitespace
            # Optional highlight lines, single- or double-quote-delimited
            (hl_lines=(?P<quot>"|')(?P<hl_lines>.*?)(?P=quot))?
            r   Úpathr$   rI   TÚhl_lines)Úrer+   r   r,   ÚcompileÚVERBOSEÚsearchÚgroupÚlowerr   Ú
IndexErrorÚinsertr-   r   rH   r?   )r.   rS   ÚlinesÚflÚcÚms         r   r@   zCodeHilite._parseHeaderÂ   s  € ó$ 	ð —‘—‘˜tÓ$ˆà�Y‰Y�q‹\ˆà�J‰Jð ð —*‘*óˆð �H‰H�R‹LˆÙð!ØŸG™G F›O×1Ñ1Ó3�”	ð �w‰w�vŒà—‘˜Q Ô#Ø�|‰|˜IÑ&Ð.°1·7±7¸9Ô3Eà*.�—‘˜YÑ'ä'5°a·g±g¸jÓ6IÓ'JˆD�L‰L˜Ò$ð �L‰L˜˜BÔà—9‘9˜UÓ#×)Ñ)¨$Ó/ˆ�øô ò !Ø �–	ð!ús   Á!$D7 Ä7E
Å	E
N)r+   rD   )T)rI   ÚboolÚreturnrD   )r`   ÚNone)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r/   rO   r@   r>   r0   r   r   r   :   s   „ ñ6ópô(9ôv50r0   r   c                  ó,   — e Zd ZU dZded<   dd„Zdd„Zy)	ÚHiliteTreeprocessorz' Highlight source code in code blocks. zdict[str, Any]Úconfigc                ór   — |j                  dd«      }|j                  dd«      }|j                  dd«      }|S )zUnescape code.r7   r6   r9   r8   r5   r4   )rE   )r.   r=   s     r   Úcode_unescapez!HiliteTreeprocessor.code_unescape  s9   € à�|‰|˜F CÓ(ˆØ�|‰|˜F CÓ(ˆð �|‰|˜G SÓ)ˆØˆr0   c           	     óö  — |j                  d«      }|D ]ã  }t        |«      dk(  sŒ|d   j                  dk(  sŒ%| j                  j	                  «       }|d   j
                  }|€ŒQt        | j                  |«      f| j                  j                  |j                  dd«      dœ|¤Ž}| j                  j                  j                  |j                  «       «      }|j                  «        d	|_        ||_        Œå y)
z, Find code blocks and store in `htmlStash`. Úprer   r   ÚcodeNÚpygments_styleÚdefault)Ú
tab_lengthÚstyleÚp)ÚiterÚlenÚtagrh   Úcopyr=   r   rj   Úmdrp   r,   Ú	htmlStashÚstorerO   Úclear)r.   ÚrootÚblocksÚblockÚlocal_configr=   rm   Úplaceholders           r   ÚrunzHiliteTreeprocessor.run  sÛ   € à—‘˜5Ó!ˆÛˆEÜ�5‹z˜Q‹ 5¨¡8§<¡<°6Ó#9Ø#Ÿ{™{×/Ñ/Ó1�Ø˜Q‘x—}‘}�Ø�<ØÜ!Ø×&Ñ& tÓ,ðà#Ÿw™w×1Ñ1Ø&×*Ñ*Ð+;¸YÓGñð #ñ	�ð #Ÿg™g×/Ñ/×5Ñ5°d·k±k³mÓD�à—‘”ð  �”	Ø(�•
ñ% r0   N)r=   rD   r`   rD   )r{   zetree.Elementr`   ra   )rb   rc   rd   re   Ú__annotations__rj   r€   r>   r0   r   rg   rg   ý   s   … Ù1àÓóô)r0   rg   c                  ó   — e Zd ZdZd„ Zd„ Zy)ÚCodeHiliteExtensionz7 Add source code highlighting to markdown code blocks. c           	     ó4  — d dgddgddgddgdd	gdd
gddgddgdœ| _         	 |j                  «       D ]U  \  }}|| j                   v r| j                  ||«       Œ't        |t        «      r	 t        |d¬«      }|dg| j                   |<   ŒW y # t        $ r Y Œw xY w)NzOUse lines numbers. True|table|inline=yes, False=no, None=auto. Default: `None`.Tz/Automatic language detection - Default: `True`.r(   z9Set class name for wrapper <div> - Default: `codehilite`.ro   z@Pygments HTML Formatter Style (Colorscheme). Default: `default`.Fz;Use inline styles instead of CSS classes - Default `False`.z\Highlight code blocks with pygments. Disable if using a JavaScript library. Default: `True`.r!   zTPrefix prepended to the language when `use_pygments` is false. Default: `language-`.r#   zDUse a specific formatter for Pygments highlighting. Default: `html`.)r%   r   r'   rn   Ú	noclassesr   r    r"   )Úpreserve_noner;   )rh   ÚitemsÚ	setConfigrC   rD   r   r   )r.   ÚkwargsÚkeyÚvalues       r   r/   zCodeHiliteExtension.__init__&  së   € ð Ðgðð ÐGðð ÐYðð Ð]ðð ÐTðð Ðtðð Ðsðð Ð^ð#ñ-
ˆŒð4 	/à Ÿ,™,ž.‰JˆC�Ø�d—k‘kÑ!Ø—‘˜s EÕ*ô ˜e¤SÔ)ðä .¨uÀDÔ I˜ð %*¨2 ;�—‘˜CÒ ñ )øô &ò Ùðús   Á*BÂ	BÂBc                ó    — t        |«      }| j                  «       |_        |j                  j	                  |dd«       |j                  | «       y)z1 Add `HilitePostprocessor` to Markdown instance. rO   é   N)rg   Ú
getConfigsrh   ÚtreeprocessorsÚregisterÚregisterExtension)r.   rw   Úhiliters      r   ÚextendMarkdownz"CodeHiliteExtension.extendMarkdownQ  s@   € ä% bÓ)ˆØŸ™Ó*ˆŒØ
×Ñ×"Ñ" 7¨H°bÔ9à
×Ñ˜TÕ"r0   N)rb   rc   rd   re   r/   r“   r>   r0   r   rƒ   rƒ   #  s   „ ÙAò)/óV#r0   rƒ   c                 ó   — t        di | ¤ŽS )Nr>   )rƒ   )r‰   s    r   ÚmakeExtensionr•   Z  s   € ÜÑ( Ñ(Ð(r0   )r   rD   r`   z	list[int])re   Ú
__future__r   r;   r   r�   r   Úutilr   Útypingr	   r
   r   Úxml.etree.ElementTreeÚetreeÚElementTreerA   r   Úpygments.lexersr   r   Úpygments.formattersr   Úpygments.utilr   ÚImportErrorr   r   rg   rƒ   r•   r>   r0   r   Ú<module>r       s…   ðñõ #å Ý *Ý !ß /Ñ /áß)Ð)ðÝ"ß>Ý9Ý+Ø€Hó
÷ }0ñ }0ôF#)˜-ô #)ôL4#˜)ô 4#ón)øði	 ò Ø‚Hðús   ±A5 Á5A?Á>A?