%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/markdown/extensions/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/markdown/extensions/__pycache__/codehilite.cpython-312.pyc

�

���e�4���dZddlmZddlmZddlmZddlmZddl	m
Z
mZmZe
r	dd	l
mcmZ	dd
lmZddlmZmZddlmZdd
lmZdZdd�ZGd�d�ZGd�de�ZGd�de�Zd�Zy	#e$rdZY�1wxYw)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�|�|sgS	ttt|j���S#t$rgcYSwxYw)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 �@/usr/lib/python3/dist-packages/markdown/extensions/codehilite.py�parse_hl_linesr*s=����	���C��T�Z�Z�\�*�+�+�����	��s�&-�;�;c�*�eZdZdZdd�Zddd�Zd	d�Zy)
�
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��||_|jdd�|_|jdd�|_|jdd�|_|jdd�|_|jdd�|_d	|vr|jd
d�|d	<d|vr|jdd
�|d<d|vrd|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�poprrrr r"�options)�selfr+r-s   r�__init__zCodeHilite.__init__ss������ '���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�|jjd�|_|j�|r|j�tr�|j
r�	t
|jfi|j��}|js|jd|_|j�|j��}t|jt�r"	t!|jfi|j��}n|jdd|i|j��}t%|j||�S|jj'dd�}|j'dd�}|j'dd	�}|j'd
d�}g}|jr5|j)dj+|j|j��|jd
r|j)d�d}|r dj+dj-|��}dj+|jd||�S#t$rl	|jr!t|jfi|j��}nt
di|j��}n$#t$rt
di|j��}YnwxYwY��wxYw#t"$rt!di|j��}Y���wxYw)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�pygmentsrr
r-rrr�aliasesr �
isinstancer"�strrrr�replace�append�format�join)r.�shebang�lexerr3�	formatter�txt�classes�	class_strs        r�hilitezCodeHilite.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� AI#�"J�#J�J�J�J�
J�J0�/J0c��ddl}|jjd�}|jd�}|j	d|j
�}|j
|�}|r�	|jd�j�|_	|jd�r|jd|�|jd� |jd�rd	|jd<t|jd
��|jd
<n|jd|�dj|�jd�|_y#t$r
d|_	Y��wxYw)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"
        rNr2a�
            (?:(?:^::+)|(?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$rIT�hl_lines)�rer+rr,�compile�VERBOSE�search�group�lowerr�
IndexError�insertr-rrHr?)r.rS�lines�fl�c�ms      rr@zCodeHilite._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�7E
�	E
N)r+rD)T)rI�bool�returnrD)r`�None)�__name__�
__module__�__qualname__�__doc__r/rOr@r>r0rrr:s��6�p�(9�v50r0rc�,�eZdZUdZded<dd�Zdd�Zy)	�HiliteTreeprocessorz' Highlight source code in code blocks. zdict[str, Any]�configc�r�|jdd�}|jdd�}|jdd�}|S)zUnescape code.r7r6r9r8r5r4)rE)r.r=s  r�
code_unescapez!HiliteTreeprocessor.code_unescapes9���|�|�F�C�(���|�|�F�C�(���|�|�G�S�)���r0c	��|jd�}|D]�}t|�dk(s�|djdk(s�%|jj	�}|dj
}|��Qt
|j|�f|jj|jdd�d�|��}|jjj|j��}|j�d	|_||_��y)
z, Find code blocks and store in `htmlStash`. �prerr�codeN�pygments_style�default)�
tab_length�style�p)�iter�len�tagrh�copyr=rrj�mdrpr,�	htmlStash�storerO�clear)r.�root�blocks�block�local_configr=rm�placeholders        r�runzHiliteTreeprocessor.runs������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�����
� ��	�(��
�%	)r0N)r=rDr`rD)r{z
etree.Elementr`ra)rbrcrdre�__annotations__rjr�r>r0rrgrg�s��1����)r0rgc��eZdZdZd�Zd�Zy)�CodeHiliteExtensionz7 Add source code highlighting to markdown code blocks. c	�4�ddgddgddgddgdd	gdd
gddgd
dgd�|_	|j�D]U\}}||jvr|j||��'t|t�r	t|d��}|dg|j|<�Wy#t$rY�wxYw)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`.roz@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%rr'rn�	noclassesrr r")�
preserve_noner;)rh�items�	setConfigrCrDrr)r.�kwargs�key�values    rr/zCodeHiliteExtension.__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�Bc��t|�}|j�|_|jj	|dd�|j|�y)z1 Add `HilitePostprocessor` to Markdown instance. rO�N)rg�
getConfigsrh�treeprocessors�register�registerExtension)r.rw�hiliters   r�extendMarkdownz"CodeHiliteExtension.extendMarkdownQs@��%�b�)�����*���
���"�"�7�H�b�9�
���T�"r0N)rbrcrdrer/r�r>r0rr�r�#s��A�)/�V#r0r�c��tdi|��S)Nr>)r�)r�s r�
makeExtensionr�Zs���(��(�(r0)rrDr`z	list[int])re�
__future__rr;rr�r�utilr�typingr	r
r�xml.etree.ElementTree�etree�ElementTreerAr�pygments.lexersr
r�pygments.formattersr�
pygments.utilr�ImportErrorrrrgr�r�r>r0r�<module>r�s����#��*�!�/�/��)�)��"�>�9�+��H�
� }0�}0�F#)�-�#)�L4#�)�4#�n)��i	���H��s�A5�5A?�>A?

Zerion Mini Shell 1.0