
    f                         d dl Z ddlmZmZ dgZ e j
                  d      Z e j
                  d      Z G d de      Z G d	 de      Z	y)
    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                       e Zd ZdZedej                  fd       Zedej                  fd       Zedej                  fd       Z	y)FencedParserfenced_directivemc                 $    | j                  d      S )Ntypegroupr
   s    U/var/www/cvtools/html/venv/lib/python3.12/site-packages/mistune/directives/_fenced.py
parse_typezFencedParser.parse_type       wwv    c                 $    | j                  d      S )Ntitler   r   s    r   parse_titlezFencedParser.parse_title   s    wwwr   c                 $    | j                  d      S )Ntextr   r   s    r   parse_contentzFencedParser.parse_content   r   r   N)
__name__
__module____qualname__namestaticmethodreMatchr   r   r    r   r   r   r      sb    Dbhh    rxx       r   r   c                   D     e Zd ZdZeZd fd	Zd Zd Zd Z	 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
    c                     t         t        |   |       || _        dj	                  d |D              }d|z   dz   | _        y )N|c              3   F   K   | ]  }t        j                  |        y w)N)r   escape).0cs     r   	<genexpr>z+FencedDirective.__init__.<locals>.<genexpr>[   s     "AA299Q<"As   !z^(?P<fenced_directive_mark>(?:z){3,})\{[a-zA-Z0-9_-]+\})superr   __init__markersjoindirective_pattern)selfpluginsr,   _marker_pattern	__class__s       r   r+   zFencedDirective.__init__X   sH    ot-g6(("A"AA-? C" " 	r   c                    t        |      }|t        |      z   }d|d   z   dz   t        |      z   dz   }t        j                  |t        j                        }|j                  |j                  |      }	|	r.|j                  ||	j                          }
|	j                         }n|j                  |d  }
|j                  }t        j                  |
      }|sy | j                  |||       |S )Nz^ {0,3}r   {z,}[ \t]*(?:\n|$))lenstrr   compileMsearchsrcstartend
cursor_max_directive_rematchparse_method)r/   blockmarkerr;   statemlencursor_start_end_pattern_end_re_end_mr   end_posr
   s                r   _process_directivez"FencedDirective._process_directivea   s    6{s6{* "S(3t94 8  	 **\2440		<899\&,,.9DjjlG99\]+D&&G%%E*r   c                 h    |j                  d      }| j                  |||j                         |      S )Nfenced_directive_mark)r   rJ   r;   )r/   rA   r
   rC   rB   s        r   parse_directivezFencedDirective.parse_directivez   s.    01&&ufaggiGGr   c                 :   |j                  d      }|rt        j                  |      s|j                  ||      S |j	                         |j
                  k\  r|j                  ||      S |j                  d      }| j                  |||j                         |      S )Nfenced_3fenced_2)r   _type_rer?   parse_fenced_codedepthmax_nested_levelrJ   r;   )r/   rA   r
   rC   inforB   s         r   rR   z!FencedDirective.parse_fenced_code~   s    wwz"8>>$/**1e44;;=E222**1e44$&&ufaggiGGr   c                     t         t        |   |       | j                  dk(  r(|j                  j                  dd | j                         y | j                  |d       y )N`~fenced_code)r*   r   __call__r,   rA   registerrR   register_block_parser)r/   mdr2   s     r   rY   zFencedDirective.__call__   sJ    ot-b1<<4HHmT43I3IJ&&r=9r   )rW   )r   r   r   __doc__r   parserr+   rJ   rM   rR   rY   __classcell__)r2   s   @r   r   r      s0    5l F
2H	H: :r   )
r   _baser   r   __all__r7   rQ   r>   r   r   r!   r   r   <module>rb      sU    	 1
 2::./

#?  o:m o:r   