o
    tf                     @   sV   d dl Z ddlmZmZ dgZe dZe dZG dd deZG d	d deZ	dS )
    N   )DirectiveParserBaseDirective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                   @   sL   e Zd ZdZedejfddZedejfddZedejfddZ	d	S )
FencedParserZfenced_directivemc                 C   
   |  dS )Ntypegroupr    r   c/var/www/html/software/conda/envs/catlas/lib/python3.10/site-packages/mistune/directives/_fenced.py
parse_type      
zFencedParser.parse_typec                 C   r   )Ntitler
   r   r   r   r   parse_title   r   zFencedParser.parse_titlec                 C   r   )Ntextr
   r   r   r   r   parse_content   r   zFencedParser.parse_contentN)
__name__
__module____qualname__namestaticmethodreMatchr   r   r   r   r   r   r   r      s    r   c                       sJ   e Zd ZdZeZd fdd	Zdd Zdd Zd	d
 Z	 fddZ
  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
    `~c                    s<   t t| | || _ddd |D }d| d | _d S )N|c                 s   s    | ]}t |V  qd S )N)r   escape).0cr   r   r   	<genexpr>[   s    z+FencedDirective.__init__.<locals>.<genexpr>z^(?P<fenced_directive_mark>(?:z){3,})\{[a-zA-Z0-9_-]+\})superr   __init__markersjoinZdirective_pattern)selfpluginsr$   Z_marker_pattern	__class__r   r   r#   X   s
   
zFencedDirective.__init__c                 C   s   t |}|t | }d|d  d t| d }t|tj}||j|}	|	r6|j||	  }
|	 }n
|j|d  }
|j	}t
|
}|sId S | ||| |S )Nz^ {0,3}r   {z,}[ \t]*(?:\n|$))lenstrr   compileMsearchsrcstartendZ
cursor_max_directive_rematchZparse_method)r&   blockmarkerr1   statemlenZcursor_startZ_end_patternZ_end_reZ_end_mr   end_posr   r   r   r   _process_directivea   s    

z"FencedDirective._process_directivec                 C   s   | d}| ||| |S )NZfenced_directive_mark)r   r:   r1   )r&   r5   r   r7   r6   r   r   r   parse_directivez   s   
zFencedDirective.parse_directivec                 C   s\   | d}|rt|s|||S | |jkr|||S | d}| ||| |S )NZfenced_3Zfenced_2)r   _type_rer4   parse_fenced_codedepthZmax_nested_levelr:   r1   )r&   r5   r   r7   infor6   r   r   r   r=   ~   s   

z!FencedDirective.parse_fenced_codec                    s@   t t| | | jdkr|jdd | j d S | |d d S )Nr   Zfenced_code)r"   r   __call__r$   r5   registerr=   Zregister_block_parser)r&   mdr(   r   r   r@      s   
zFencedDirective.__call__)r   )r   r   r   __doc__r   parserr#   r:   r;   r=   r@   __classcell__r   r   r(   r   r      s    6	)
r   _baser   r   __all__r-   r<   r3   r   r   r   r   r   r   <module>   s    
