
    Ki*                     h    d Z ddlZddlmZmZmZ ddlmZ erddlm	Z	m
Z
 ddlmZmZ  G d d      Zy)	z!Markdown documentation formatter.    N)TYPE_CHECKINGAnyOptional)extract_text)ConsoleConsoleOptions)	HelpEntry	HelpPanelc                       e Zd ZdZ	 	 	 ddededefdZddZdefd	Z	d
e
d   de
d   ddddfdZded   d
e
d   ddfdZded   d
e
d   ddfdZd
e
d   de
d   deddfdZd
e
d   de
d   deddfdZy)MarkdownFormattera  Markdown documentation formatter.

    Parameters
    ----------
    heading_level : int
        Starting heading level for panels (default: 2).
        E.g., 2 produces "## Commands", 3 produces "### Commands".
    table_style : str
        Style for parameter/command tables: "table" or "list" (default: "table").
    include_hidden : bool
        Include hidden commands/parameters in documentation (default: False).
    heading_leveltable_styleinclude_hiddenc                 `    || _         || _        || _        t        j                         | _        y )N)r   r   r   ioStringIO_output)selfr   r   r   s       m/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/cyclopts/help/formatters/markdown.py__init__zMarkdownFormatter.__init__   s)     +&,{{}    returnNc                 6    t        j                         | _        y)z!Reset the internal output buffer.N)r   r   r   r   s    r   resetzMarkdownFormatter.reset'   s    {{}r   c                 6    | j                   j                         S )zGet the accumulated markdown output.

        Returns
        -------
        str
            The markdown documentation string.
        )r   getvaluer   s    r   
get_outputzMarkdownFormatter.get_output+   s     ||$$&&r   consoler   optionsr   panelr
   c                 *   |j                   sy|j                  rFt        |j                  |      }d| j                  z  }| j                  j                  | d| d       |j                  r6t        |j                  |      }|r| j                  j                  | d       |j                  dk(  r| j                  |j                   |       n+|j                  dk(  r| j                  |j                   |       | j                  j                  d       y)ag  Format and render a help panel as markdown.

        Parameters
        ----------
        console : Optional[Console]
            Console for rendering (used for extracting plain text).
        options : Optional[ConsoleOptions]
            Console rendering options (unused for markdown).
        panel : HelpPanel
            Help panel to render.
        N# 

command	parameter
)
entriestitler   r   r   writedescriptionformat_format_command_panel_format_parameter_panel)r   r   r    r!   
title_textheading	desc_texts          r   __call__zMarkdownFormatter.__call__5   s    " }} ;;%ekk7;JD...GLL'!J<t<= $U%6%6@I""i[#56 <<9$&&u}}g>\\[(((@4 r   r)   r	   c                 h   |D ]  }|j                   x}s|d   |dd }}|r| ddj                  |       d}n|}t        |j                  |d      }|r"| j                  j                  d	| d
|        n| j                  j                  d	| d       | j                  j                  d        y)zFormat command entries as markdown.

        Parameters
        ----------
        entries : list[HelpEntry]
            Command entries to format.
        console : Optional[Console]
            Console for text extraction.
        r      Nz (, )Tpreserve_markup* ``: z`:r(   )all_optionsjoinr   r,   r   r+   )	r   r)   r   entrynamesprimary_namealiasesname_displaydescs	            r   r.   z'MarkdownFormatter._format_command_panel]   s      	)E)))u)(-a%)g&2^2dii6H5I#KL#/L#E$5$5wPTULL&&\N#dV'DELL&&\N"'=>""4(	)r   c                    |D ]  }|j                   x}s|D cg c]  }|j                  d      r| }}|D cg c](  }|j                  d      s|j                  d      r'|* }}|D cg c]  }|j                  d      s| }}|j                  xr |j                  du }	|	r9|r7|d   j	                         g}
|
j                  |       dj                  |
      }na|rdj                  ||z         }nJ|r7|d   j	                         g}
|
j                  |       dj                  |
      }ndj                  |      }| j                  j                  d| d       t        |j                  |d	      }|r%ddl}|j                  d
      }| j                  j                  |d          d}|dd D ]  }|j                         s| j                  j                  d
       /|j                         }t        |      t        |      z
  }|j!                  d|      rd}t#        |dz   d      }nK|j!                  d|      r|rt#        |dz   d      }n'|j!                  d|      rt#        |dz   d      }n|dz   }| j                  j                  d
d|z  z   |z           d}|j                  r|	sd}n|	r|j                  rd}g }|j$                  r/dj                  |j$                        }|j'                  d|        |j(                  r/dj                  |j(                        }|j'                  d|        |j                  *t        |j                  |      }|j'                  d|        |r| j                  j                  d       |D ]!  }| j                  j                  d| d       # | j                  j                  d
        yc c}w c c}w c c}w )zFormat parameter entries as markdown in Typer style.

        Parameters
        ----------
        entries : list[HelpEntry]
            Parameter entries to format.
        console : Optional[Console]
            Console for text extraction.
        -z--Nr   r6   r:   r;   Tr8   r(   Fr5   z^\d+\.   z^\-
   r$   z	choices: zenv: z	default: z  **[required]**z  *[z]*)r<   
startswithrequireddefaultupperextendr=   r   r+   r   r,   resplitstriplstriplenmatchmaxchoicesappendenv_var)r   r)   r   r>   r?   npositional_names
short_opts	long_optsis_positionalpartsname_strrC   rM   linesin_numbered_listlinestrippedexisting_indentindentis_requiredmetadatachoices_strenv_strdefault_stritems                             r   r/   z)MarkdownFormatter._format_parameter_panely   s     c	)E)))u)/4#N!ALL<MA#N #N)._A!,,s2CALLY]L^a_
_(-D1d1CQD	D !& H5==D3H %5-a06689ELL+#yy/H "#'99Y-C#D)!1!!4!:!:!< =Y/#'99U#3#'99Y#7 ""S
##67 $E$5$5wPTU !JJt,ELL&&uQx0 (-$ %ab	 O#zz| LL..t4'+{{}H.1$i#h-.GO  "xx	8<37 0),_q-@!)D!#&(!;@P *-_q-@")E!#&(!;),_q-@!)D *91)< LL..tcFl/BX/MN1O8 $>>-"&K"u~~"&K=="&))EMM":KOOi}$=>=="ii6GOOeG9$56==,".u}}g"FKOOi}$=> LL&&'9: % 8DLL&&dV278 ""4(Gc	) $O_Ds'   OOOO$O.OOusagec                     |rnt        ||      }|r_|j                         j                  d      s | j                  j	                  d| d       y| j                  j	                  d| d       yyy)a2  Render the usage line as markdown.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        usage : Any
            The usage line content.
        zUsage:z```
Usage: z
```

z```
N)r   rO   rH   r   r+   )r   r   r    rj   
usage_texts        r   render_usagezMarkdownFormatter.render_usage   sm    " %eW5J!'')44X>LL&&j\'KLLL&&zl)'DE  r   r,   c                 d    |r.t        ||      }|r| j                  j                  | d       yyy)a:  Render the description as markdown.

        Parameters
        ----------
        console : Optional[Console]
            Console for text extraction.
        options : Optional[ConsoleOptions]
            Console rendering options (unused).
        description : Any
            The description content.
        r%   N)r   r   r+   )r   r   r    r,   r2   s        r   render_descriptionz$MarkdownFormatter.render_description  s9    " $[':I""i[#56  r   )   tableF)r   N)__name__
__module____qualname____doc__intstrboolr   r   r   r   r3   listr.   r/   r   rm   ro    r   r   r   r      s=    "$		%	% 	% 		%%'C '&!)$&! *+&! 	&!
 
&!P)T+-> )R[I\ )ae )8n)tK/@ n)8T]K^ n)cg n)`F)$F *+F 	F
 
F47)$7 *+7 	7
 
7r   r   )ru   r   typingr   r   r   cyclopts._markupr   rich.consoler   r   cyclopts.helpr	   r
   r   rz   r   r   <module>r      s)    ' 	 / / )42I7 I7r   