o
    §iHB  ã                   @   sà   d Z ddlmZ ddlmZ ddlmZ erddlmZ 	ddd	d
e	de
deee
e
d	f  fdd„Z	d dee
 deee
e
d	f  dede
dB ddf
dd„Z						d!dd	de	d
e	dedee
 dB de	de	de
fdd„ZdS )"z5Documentation generation functions for cyclopts apps.é    )ÚTYPE_CHECKING)Úextract_text)ÚBaseDocGenerator)ÚAppFÚ Úappr   Úinclude_hiddenÚprefixÚreturnc           	      C   sz   g }| j s|S t | |¡D ]-\}}|r|› |› n|}| dd¡ ¡ }| |||f¡ t|||› dd}| |¡ q|S )zwRecursively collect all commands for table of contents.

    Returns a list of (display_name, anchor, app) tuples.
    ú ú-)r   r	   )Ú	_commandsr   Úiterate_commandsÚreplaceÚlowerÚappendÚ_collect_commands_for_tocÚextend)	r   r   r	   ÚcommandsÚnameÚsubappÚdisplay_nameÚanchorÚnested© r   ú\/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/cyclopts/docs/markdown.pyr      s   r   NÚlinesr   ÚlevelÚapp_namec              	   C   s’   |D ]D\}}}|  d¡}d| }| ¡ d }	|r$|dkr$|› d|› }
n|r.|› d|› }
n|}
|
 ¡  dd¡}|  |› d|	› d|› d¡ qd	S )
z-Generate TOC entries with proper indentation.r   z  éÿÿÿÿr   r   z- [`z`](#ú)N)ÚcountÚsplitr   r   r   )r   r   r   r   r   r   Ú_appÚdepthÚindentÚcmd_nameÚ	full_namer   r   r   Ú_generate_toc_entries'   s   
ìr(   Té   Ú	recursiveÚheading_levelÚcommand_chainÚgenerate_tocÚflatten_commandsc           ;      C   sÞ  ddl m} g }|du rg }t | |¡\}	}
}|rd|
› dn|}| d| › d|› ¡ | d¡ | jjdd	d
}t | |¡}|r[|dv }t|d|d}|r[| | 	¡ ¡ | d¡ |r|s| j
rt| |d}|r| d¡ | d¡ t||d|	d | d¡ t | ¡}|r½| d¡ | d¡ | d¡ t|tƒrŸ|}nt|ddd}tj||dd}| |¡ | d¡ | d¡ |  g |¡}t ||¡}|d }|d }|d }|d }||d |dd}|r| d¡ |D ]\}}| ¡  d|_|dd|ƒ | ¡  	¡ }|r| |¡ qì| d¡ |rA| d¡ |D ] \}}| ¡  d|_|dd|ƒ | ¡  	¡ }|r:| |¡ q| d¡ |rƒ|D ]<\}}|jr| d|j› d ¡ | ¡  |jd|j|j|jd!}|dd|ƒ | ¡  	¡ }|r|| |¡ | d¡ qF|r³| d"¡ |D ] \}}| ¡  d|_|dd|ƒ | ¡  	¡ }|r¬| |¡ q| d¡ | j
rät | |¡D ]%\} }!t || |	¡}"|rÏ|}#n|d }#| d|# › d#d |"¡› d¡ | d¡ |! |!g¡± |!jjd|d
}$|$dv }%t |!|$¡}&|&rt|&d|%d}'|'r| |' 	¡ ¡ | d¡ t |!¡}(|(rY| d¡ | d¡ | d¡ t|(tƒr;|(})nt|(ddd})tj|)|"dd}| |¡ | d¡ | d¡ |r™|! g |$¡}*t |*|¡}+|+d },|+d }-|+d }.|+d }/|r€|d }0n|d$ }0||0|dd}1|,r¸| d¡ |,D ]\}}|1 ¡  |1dd|ƒ |1 ¡  	¡ }|r±| |¡ q•| d¡ |-rå| d¡ |-D ]\}}|1 ¡  |1dd|ƒ |1 ¡  	¡ }|rÞ| |¡ qÂ| d¡ |.r'|.D ]<\}}|jr%| d|j› d ¡ |1 ¡  |jd|j|j|jd!}|1dd|ƒ |1 ¡  	¡ }|r | |¡ | d¡ qê|/r™|o/|!j
}2|2ro| d"¡ |/D ].\}}|jD ]%}3|3jre|3jd }4|3jrXt|3jd|%dnd}| d%|4› d&|› ¡ qAq:| d¡ n*| d"¡ |/D ]\}}|1 ¡  |1dd|ƒ |1 ¡  	¡ }|r’| |¡ qv| d¡ W d  ƒ n	1 s¤w   Y  |râ|!j
rât |!|¡D ]+\}5}6t |"|5|	¡}7|rÇ|}8n|d }8t|6|||8|7d|d'}9| |9¡ | d¡ q¶q½d( |¡ ¡ d( }:|:S ))a¾  Generate markdown documentation for a CLI application.

    Parameters
    ----------
    app : App
        The cyclopts App instance to document.
    recursive : bool
        If True, generate documentation for all subcommands recursively.
        Default is True.
    include_hidden : bool
        If True, include hidden commands/parameters in documentation.
        Default is False.
    heading_level : int
        Starting heading level for the main application title.
        Default is 1 (single #).
    command_chain : list[str]
        Internal parameter to track command hierarchy.
        Default is None.
    generate_toc : bool
        If True, generate a table of contents for multi-command apps.
        Default is True.
    flatten_commands : bool
        If True, generate all commands at the same heading level instead of nested.
        Default is False.

    Returns
    -------
    str
        The generated markdown documentation.
    r   )ÚMarkdownFormatterNú`ú#r   r   Úhelp_formatÚrestructuredtext)Úfallback)ÚmarkdownÚmd)Úpreserve_markup)r   z## Table of Contents)r   r   z
**Usage**:z
```consoleFú$)r	   z```r   Ú	argumentsÚoptionsÚgroupedr)   Úlist)r+   r   Útable_stylez**Arguments**:
z**Options**:
z**z**:
)ÚtitleÚentriesÚformatÚdescriptionz**Commands**:
z `é   z* `z`: )r*   r   r+   r,   r-   r.   Ú
) Ú!cyclopts.help.formatters.markdownr/   r   Úget_app_infor   Ú	app_stackÚresolveÚextract_descriptionr   Ústripr   r   r(   Úextract_usageÚ
isinstanceÚstrÚformat_usage_lineÚ_assemble_help_panelsÚcategorize_panelsÚresetr>   Ú
get_outputÚ	__class__r?   r@   rA   r   Úbuild_command_chainÚjoinÚnamesÚgenerate_markdown_docsÚrstrip);r   r*   r   r+   r,   r-   r.   r/   r   r   Úfull_commandÚ
base_titler>   r2   rA   ÚpreserveÚ	desc_textÚtoc_commandsÚusageÚ
usage_textÚ
usage_lineÚhelp_panels_with_groupsÚcategorizedÚcommand_panelsÚargument_panelsÚoption_panelsÚgrouped_panelsÚ	formatterÚ_groupÚpanelÚoutputÚ
panel_copyr   r   Úsub_command_chainÚsub_heading_levelÚsub_help_formatÚpreserve_subÚsub_descriptionÚsub_desc_textÚ	sub_usageÚsub_usage_textÚ
sub_panelsÚsub_categorizedÚsub_argument_panelsÚsub_option_panelsÚsub_grouped_panelsÚsub_command_panelsÚpanel_heading_levelÚsub_formatterÚwill_recurseÚentryr&   Únested_nameÚ
nested_appÚnested_command_chainÚnested_heading_levelÚnested_docsÚdocr   r   r   rV   B   sÀ  '












ý

€


€
ü

€

€
 









ÿ

€


€
ü

€


ÿý€ø	

€
€vÿù

€rV   )Fr   )r   N)TFr)   NTF)Ú__doc__Útypingr   Úcyclopts._markupr   Úcyclopts.docs.baser   Úcyclopts.corer   ÚboolrL   r<   Útupler   Úintr(   rV   r   r   r   r   Ú<module>   sf    ÿÿÿÿ
þÿÿÿÿÿ
þùÿþýü
ûúùø