
    ^h                         S SK r S SKJrJrJrJr  SSKJrJrJ	r	  \(       a  SSK
Jr  SSKJr  SSKJr  S	/r\ R"                  " S
5      r\ R"                  " S5      r " S S\5      r " S S	\5      rg)    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                   ~    \ rS rSrSr\S\\   S\4S j5       r\S\\   S\4S j5       r	\S\\   S\4S j5       r
Srg	)
FencedParser   fenced_directivemreturnc                 $    U R                  S5      $ )Ntypegroupr   s    T/home/james-whalen/.local/lib/python3.13/site-packages/mistune/directives/_fenced.py
parse_typeFencedParser.parse_type       wwv    c                 $    U R                  S5      $ )Ntitler   r   s    r   parse_titleFencedParser.parse_title   s    wwwr   c                 $    U R                  S5      $ )Ntextr   r   s    r   parse_contentFencedParser.parse_content"   r   r    N)__name__
__module____qualname____firstlineno__namestaticmethodr   strr   r"   r&   __static_attributes__r(   r   r   r   r      sw    DeCj S    uSz  c     s   r   r   c                      ^  \ rS rSrSr\rSS\\   S\	SS4U 4S jjjr
SS	S
\	S\SSS\\   4
S jrSS	S\\	   SSS\\   4S jrSS	S\\	   SSS\\   4S jrSU 4S jjrSrU =r$ )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                    > [         [        U ]  U5        X l        SR	                  S U 5       5      nSU-   S-   U l        g )N|c              3   N   #    U  H  n[         R                  " U5      v   M     g 7f)N)reescape).0cs     r   	<genexpr>+FencedDirective.__init__.<locals>.<genexpr>d   s     "AA299Q<<s   #%z^(?P<fenced_directive_mark>(?:z){3,})\{[a-zA-Z0-9_-]+\})superr   __init__r4   joindirective_pattern)selfr3   r4   _marker_pattern	__class__s       r   r?   FencedDirective.__init__a   sF    ot-g6(("A"AA-? C" " 	r   blockr   markerstartstater   c                    [        U5      nU[        U5      -   nSUS   -   S-   [        U5      -   S-   n[        R                  " U[        R                  5      nUR                  UR                  U5      n	U	(       a-  UR                  XiR                  5        n
U	R                  5       nOUR                  US  n
UR                  n[        R                  U
5      nU(       d  g U R                  XU5        U$ )Nz^ {0,3}r   {z,}[ \t]*(?:\n|$))lenr/   r8   compileMsearchsrcrH   end
cursor_max_directive_rematchparse_method)rB   rF   rG   rH   rI   mlencursor_start_end_pattern_end_re_end_mr%   end_posr   s                r   _process_directive"FencedDirective._process_directivej   s    6{s6{* "S(3t94 8  	 **\2440		<899\LLN;DjjlG99\]+D&&G%%E*r   r   c                 f    UR                  S5      nU R                  XUR                  5       U5      $ )Nfenced_directive_mark)r   r\   rH   )rB   rF   r   rI   rG   s        r   parse_directiveFencedDirective.parse_directive   s,    01&&uaggiGGr   c                 J   UR                  S5      nU(       a  [        R                  U5      (       d  UR                  X#5      $ UR	                  5       UR
                  :  a  UR                  X#5      $ UR                  S5      nU R                  XUR                  5       U5      $ )Nfenced_3fenced_2)r   _type_rerT   parse_fenced_codedepthmax_nested_levelr\   rH   )rB   rF   r   rI   inforG   s         r   rf   !FencedDirective.parse_fenced_code   s    wwz"8>>$//**144;;=E222**144$&&uaggiGGr   c                    > [         [        U ]  U5        U R                  S:X  a(  UR                  R                  SS U R                  5        g U R                  US5        g )N`~fenced_code)r>   r   __call__r4   rF   registerrf   register_block_parser)rB   mdrD   s     r   rn   FencedDirective.__call__   sJ    ot-b1<<4HHmT43I3IJ&&r=9r   )rA   r4   )rl   )rq   r   r   N)r)   r*   r+   r,   __doc__r   parserr   r
   r/   r?   intr   r\   r   r`   rf   rn   r0   __classcell__)rD   s   @r   r   r   '   s    5n F
_ 5 
 
t 
 
 s 3 Wc hpqthu 2H] HuSz H, H[cdg[h H	H} 	Hs 	HL 	H]efi]j 	H: :r   )r8   typingr   r   r   r   _baser   r	   r
   block_parserr   corer   markdownr   __all__rM   re   rS   r   r   r(   r   r   <module>r}      sh    	 7 7 B B*!# 
 ::./

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