
    Mh                         d dl Z d dlmZmZmZmZ ddlmZmZm	Z	 erddl
mZ ddlmZ ddlmZ d	gZ e j        d
          Z e j        d          Z G d de          Z G d d	e          ZdS )    N)TYPE_CHECKINGListMatchOptional   )BaseDirectiveDirectiveParserDirectivePlugin   )BlockParser)
BlockState)MarkdownFencedDirectivez^ *\{[a-zA-Z0-9_-]+\}z\{(?P<type>[a-zA-Z0-9_-]+)\} *(?P<title>[^\n]*)(?:\n|$)(?P<options>(?:\:[a-zA-Z0-9_-]+\: *[^\n]*\n+)*)\n*(?P<text>(?:[^\n]*\n+)*)c                       e Zd ZdZedee         defd            Zedee         defd            Zedee         defd            Z	dS )FencedParserfenced_directivemreturnc                 ,    |                      d          S )Ntypegroupr   s    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mistune/directives/_fenced.py
parse_typezFencedParser.parse_type       wwv    c                 ,    |                      d          S )Ntitler   r   s    r   parse_titlezFencedParser.parse_title   s    wwwr   c                 ,    |                      d          S )Ntextr   r   s    r   parse_contentzFencedParser.parse_content"   r   r   N)
__name__
__module____qualname__namestaticmethodr   strr   r    r#    r   r   r   r      s        DeCj S    \  uSz  c       \  s     \  r   r   c                        e Zd ZdZeZddee         deddf fdZ	dd	d
ede
dddee
         f
dZdd	dee         dddee
         fdZdd	dee         dddee
         fdZd fdZ xZS )r   a  A **fenced** style of directive looks like a fenced code block, it is
    inspired by markdown-it-docutils. The syntax looks like:

    .. code-block:: text

        ```{directive-type} title
        :option-key: option value
        :option-key: option value

        content text here
        ```

    To use ``FencedDirective``, developers can add it into plugin list in
    the :class:`Markdown` instance:

    .. code-block:: python

        import mistune
        from mistune.directives import FencedDirective, Admonition

        md = mistune.create_markdown(plugins=[
            # ...
            FencedDirective([Admonition()]),
        ])

    FencedDirective is using >= 3 backticks or curly-brackets for the fenced
    syntax. Developers can change it to other characters, e.g. colon:

    .. code-block:: python

            directive = FencedDirective([Admonition()], ':')

    And then the directive syntax would look like:

    .. code-block:: text

        ::::{note} Nesting directives
        You can nest directives by ensuring the start and end fence matching
        the length. For instance, in this example, the admonition is started
        with 4 colons, then it should end with 4 colons.

        You can nest another admonition with other length of colons except 4.

        :::{tip} Longer outermost fence
        It would be better that you put longer markers for the outer fence,
        and shorter markers for the inner fence. In this example, we put 4
        colons outsie, and 3 colons inside.
        :::
        ::::

    :param plugins: list of directive plugins
    :param markers: characters to determine the fence, default is backtick
                    and curly-bracket
    `~pluginsmarkersr   Nc                     t          t          |                               |           || _        d                    d |D                       }d|z   dz   | _        d S )N|c              3   >   K   | ]}t          j        |          V  d S )N)reescape).0cs     r   	<genexpr>z+FencedDirective.__init__.<locals>.<genexpr>d   s*      "A"AA29Q<<"A"A"A"A"A"Ar   z^(?P<fenced_directive_mark>(?:z){3,})\{[a-zA-Z0-9_-]+\})superr   __init__r.   joindirective_pattern)selfr-   r.   _marker_pattern	__class__s       r   r8   zFencedDirective.__init__a   si    ot$$--g666(("A"A"A"A"AAA-? C" " 	r   blockr   markerstartstater   c                    t          |          }|t          |          z   }d|d         z   dz   t          |          z   dz   }t          j        |t          j                  }|                    |j        |          }	|	r6|j        ||	                                         }
|	                                }n|j        |d          }
|j	        }t                              |
          }|sd S |                     |||           |S )Nz^ {0,3}r   {z,}[ \t]*(?:\n|$))lenr)   r2   compileMsearchsrcr@   end
cursor_max_directive_rematchparse_method)r;   r>   r?   r@   rA   mlencursor_start_end_pattern_end_re_end_mr"   end_posr   s                r   _process_directivez"FencedDirective._process_directivej   s    6{{s6{{* "S(3t994 8  	 *\2400	<88 	'9\FLLNN:;DjjllGG9\]]+D&G%% 	4%E***r   r   c                     |                     d          }|                     |||                                |          S )Nfenced_directive_mark)r   rT   r@   )r;   r>   r   rA   r?   s        r   parse_directivezFencedDirective.parse_directive   s6    011&&ufaggiiGGGr   c                 t   |                     d          }|rt                              |          s|                    ||          S |                                |j        k    r|                    ||          S |                     d          }|                     |||                                |          S )Nfenced_3fenced_2)r   _type_rerL   parse_fenced_codedepthmax_nested_levelrT   r@   )r;   r>   r   rA   infor?   s         r   r\   z!FencedDirective.parse_fenced_code   s    wwz"" 	58>>$// 	5**1e444;;==E222**1e444$$&&ufaggiiGGGr   mdr   c                     t          t          |                               |           | j        dk    r#|j                            dd | j                   d S |                     |d           d S )Nr,   fenced_code)r7   r   __call__r.   r>   registerr\   register_block_parser)r;   r`   r=   s     r   rc   zFencedDirective.__call__   sm    ot$$--b111<4HmT43IJJJJJ&&r=99999r   )r,   )r`   r   r   N)r$   r%   r&   __doc__r   parserr   r
   r)   r8   intr   rT   r   rW   r\   rc   __classcell__)r=   s   @r   r   r   '   sQ       5 5n F
 
_ 5 
 
t 
 
 
 
 
 
 s 3 Wc hpqthu    2H] HuSz H, H[cdg[h H H H H	H} 	Hs 	HL 	H]efi]j 	H 	H 	H 	H: : : : : : : : : :r   )r2   typingr   r   r   r   _baser   r	   r
   block_parserr   corer   markdownr   __all__rE   r[   rK   r   r   r*   r   r   <module>rp      s,   				 7 7 7 7 7 7 7 7 7 7 7 7 B B B B B B B B B B $******!!!!!!###### 
 2:.//
#     ?    p: p: p: p: p:m p: p: p: p: p:r   