a
    ö£Be  ã                   @   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ejdœdd„ƒZeejdœdd„ƒZeejdœdd„ƒZ	d	S )
ÚFencedParserZfenced_directive©Úmc                 C   s
   |   d¡S )NÚtype©Úgroupr   © r   ú]/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/mistune/directives/_fenced.pyÚ
parse_type   s    zFencedParser.parse_typec                 C   s
   |   d¡S )NÚtitler
   r   r   r   r   Úparse_title   s    zFencedParser.parse_titlec                 C   s
   |   d¡S )NÚtextr
   r   r   r   r   Úparse_content   s    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>[   ó    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|¡}	|	rl|j||	 ¡ … }
|	 ¡ }n|j|d … }
|j	}t
 |
¡}|s’d 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Úmarkerr0   Ú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   r9   r0   )r%   r4   r   r6   r5   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_rer3   Úparse_fenced_codeÚdepthZmax_nested_levelr9   r0   )r%   r4   r   r6   Úinfor5   r   r   r   r<   ~   s    

z!FencedDirective.parse_fenced_codec                    s>   t t| ƒ |¡ | jdkr.|j dd | j¡ n|  |d¡ d S )Nr   Zfenced_code)r!   r   Ú__call__r#   r4   Úregisterr<   Zregister_block_parser)r%   Úmdr'   r   r   r?   ‰   s    
zFencedDirective.__call__)r   )r   r   r   Ú__doc__r   Úparserr"   r9   r:   r<   r?   Ú__classcell__r   r   r'   r   r      s   6	)
r   Ú_baser   r   Ú__all__r,   r;   r2   r   r   r   r   r   r   Ú<module>   s   
ÿ